简体   繁体   中英

UILocalNotification show view after notification happens?

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.applicationIconBadgeNumber-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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM