mamo10
mamo10

Reputation: 5

iOS local notification open specific view

I would like to open a specific view because otherwise it would not make sense to make the notification. On stackoverflow the majority of the questions are about tabbed app.. but I have a view controller.

This is my local notification:

UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"Test";
notification.applicationIconBadgeNumber = 1;

[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

and this is the code that I have found for my app delegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

self.mainVC = [[UIViewController alloc] initWithNibName:@"MyTestViewController" bundle:nil];
self.window.rootViewController = self.mainVC;
[self.window makeKeyAndVisible];

application.applicationIconBadgeNumber = 0;
return YES;
}

I tried to integrate it into my app, but this is the error: Property 'mainVC' not found on object of type 'AppDelegate'.

I would like to open 'MyTestViewController'. Can someone please explain to me how can I do? thank you very much

Upvotes: 0

Views: 1575

Answers (3)

Suhail kalathil
Suhail kalathil

Reputation: 2693

Import

#import MyTestViewController.h

create a property

@property(nonatomic, strong) MyTestViewController * myTestViewController;

And

self.myTestViewController = [[MyTestViewController alloc] initWithNibName:@"MyTestViewController" bundle:nil];
self.window.rootViewController = self.myTestViewController;

Upvotes: 0

LLIAJLbHOu
LLIAJLbHOu

Reputation: 1313

Try it->

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    //present your controller here, for example
    self.myTestViewController = [[UIViewController alloc] initWithNibName:@"MyTestViewController" bundle:nil];
    [self.window.rootViewController pushViewController:self.myTestViewController animated:YES];
}

Upvotes: 0

camimvogelsang
camimvogelsang

Reputation: 289

There is no such thing as a mainVC unless you've declared it somewhere. Assuming that you mean you want to set a view controller which is of the class MyTestViewController, you can do:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    MyTestViewController *myTestVC = [MyTestViewController new];
    self.window.rootViewController = myTestVC;
    [self.window makeKeyAndVisible];
    return YES;
}

If your app is single view, you can use the "Single View Application" template in Xcode to get started.

enter image description here

Upvotes: 0

Related Questions