user1366911
user1366911

Reputation: 917

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.

Upvotes: 3

Views: 275

Answers (1)

Ash Furrow
Ash Furrow

Reputation: 12421

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.

Upvotes: 3

Related Questions