Closed psajja closed 9 years ago
Yes. You should do it here:
AppDelegate.m
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler
{
if ([identifier isEqualToString: @"??????"]) { //this if statement is up to you
//change tab bar here
UITabBarController *tab = (UITabBarController *)self.window.rootViewController;
tab.selectedIndex = 2;
}
// Must be called when finished
completionHandler();
}
Let me know if this works.
Notice I updated the code.
Thanks Jonny. I tried this but it appears to me that this method is not called when I click on the local notification. I tried to call the other method and it works fine.
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif{
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler
is for interactive notifications.
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif{}
is for non-interactive notifications where you click on the notification.
Thanks. Now it works !!
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);
// Launch check in tab
UITabBarController *tab = (UITabBarController *)self.window.rootViewController;
tab.selectedIndex = 2;
}
Yep! There you go. Thanks Andrew.
For some reason, Apples documentation makes it sound like
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { }
only works if the app is in the foreground. "Handling a local notification when an app is already running". Obviously this isn't the case.
Thank you Jonny and Andrew.
My application has a tab bar view controller with 3 view controllers.
When the user clicks on the local notification, I would like to have the 3rd tab of the tab bar view controller be displayed. Is there a method to get a handle on all the list of view controller in the tab bar vc? Thanks.