I am using UILocalNotification. When the notification shows, and the user clicks my alertAction, how can I direct them to a specific view when my app loads? (Similar to how the calendar app shows you the event that just was alerted).
I am using:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOption {
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSString *itemName = [localNotif.userInfo objectForKey:ItemListKey];
// [viewController displayItem:itemName]; // custom method
application.applicationIconBadgeNumber = localNotif.a开发者_JAVA技巧pplicationIconBadgeNumber-1;
NSLog(@"has localNotif %@",itemName);
}
return YES;
}
You need to structure your application view controllers so that you can show a particular view from within the applicationLaunch. That may mean, for example, programmatically re-creating your entire view controller structure without the benefit of any user interactions. You may have to manually select tab bar tabs, manually create navigation controller stacks, etc.
Edit: additionally, there are three cases to handle with local notifications:
the app receives the local notification and was brought from background to foreground (so all your view controller structures are already intact, but you still have to manually "navigate" to the right place)
the app receives the local notification and was already running in the foreground
the app was just launched
精彩评论