Reputation: 27
I have an app that using local notifications, I want to have the app load a different page when a notification is recived. I also want it to load this new view when the slide to unlock over the notification is used.
My storyboards do not have a navigation controller is this possible to be done?
Upvotes: 0
Views: 532
Reputation: 419
You can handle local notifications in the following ways:
Add in following method located in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
This code:
// Handle launching from a notification
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (locationNotification) {
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
// redirect to UIViewController
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:[NSBundle mainBundle]];
UIViewController * notificationViewController = [storyBoard instantiateViewControllerWithIdentifier:@"IdentifierOfViewController"];
self.window.rootViewController = notificationViewController; // set the new UIViewController
}
This allows you to handle LOCAL notifications as soon as the app is launched, either by acting on a 'slide to view' dialog or just by opening the app. You can then change the rootViewController in the application if there is a notification
My storyboards do not have a navigation controller is this possible to be done?
Yes, this wouldn't be a problem as long you use modal navigation.
EDIT
If you want to handle the notifications if the app is currently opened by the user you can catch the notification, by placing the following method in the AppDelegate:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Upvotes: 1