简体   繁体   中英

UILocalNotification - How to discover whether user action came from notification center?

In the method that get called when a notification is executed:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

Is there a way to discover whether the notification came from the user tapping an alert in the notification center, or whether the alert was received while the app was running?

The reason is: I want to direct the user to a specific page when they tap an alert. That method above gets called if an alert goes off while the user is inside the app (hence, they didn't tap the alert in the notification center), and I don't want to kick them to another screen.

However, if the app is running, or in background, and they've pulled down the notification center, I do want to bring them to a specific screen and that same method is called in those situations.

You can't, unfortunately, do exactly what you want to do. The closest you can come is

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    if (application.applicationState == UIApplicationStateActive)
        // They didn't come from the notification area
    else
        // They did
}

Unfortunately there is no context information supplied while receiving alerts.

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