I’ve got a question regarding displaying local notification reminders inside the application. I think the problem lies with the view controller.
here’s the code I have so far:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[Number1ViewController alloc] initWithNibName:@"Number1ViewController_iPhone" bundle:nil];
viewController2 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPhone" bundle:nil];
} else {
viewController1 = [[Number1ViewController alloc] initWithNibName:@"Number1ViewController_iPad" bundle:nil];
viewController2 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSString *stringReminder = [notification.userInfo
objectForKey:@"TextforReminder"];
[viewController showReminder:stringReminder];
}
}
application.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
or:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
application.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSString *stringReminder = [notification.userInfo
objectForKey:@"TextforReminder"];
[viewController showReminder:stringReminder];
}
}
However I am getting errors regarding the view Controller. Use of undeclared identifier ‘viewController’. I understand that this is becuase there is no view controller, however I don’t unterstand how I have to achieve, that the Reminder is shown in the process.
Thanks a lot for your help, I am not getting further in this problem.
Cheers
As your warning is trying to tell you the problem in
application:didFinishLaunchingWithOptions:is in.UIViewControllerhas no method namedshowReminder:, so I assume it’s in your subclass of one of yourUIViewControllersubclasses.You need to do two things,
1) Replace ‘
viewController‘ with either ‘viewController1‘ or ‘viewController2‘ whichever has the methodshowReminder:2) You need to wait until these viewControllers are actually on screen before presenting more views on top of them. So move the block above to after the
[self.window makeKeyAndVisible]but beforereturn YES.Edited as comment says
SettingViewControllerwill have theshowReminder:method;As far as the problem receiving
LocalNotificationswhile the app is running. If your app is simple then maybe just replace ‘viewController‘ with:(SettingsViewController *)[self.tabBarController.viewControllers objectAtIndex:1]Since in your code you add it as the second element of the
viewControllersproperty.