Question

My goal is to open a specific screen when user clicks on a UILocalNotification from the iOS Notification Center.

Now if the app is being resumed from the background when user acts on the Notification, I notice didReceiveLocalNotification is called:

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

Now I can get the userInfo dictionary from the UILocalNotification object and opens the proper screen.

Unfortunately, this same method is called also when my app publishes a UILocationNotification while the app is running in the foreground:

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

How would I distinguish between the 2 cases?

Was it helpful?

Solution

It passes to you the application object that contains the state in its .applicationState property.

Consequently, you can make sure it is not active by testing...

if (application.applicationState != UIApplicationStateActive){
 // do your stuff
}

And that's it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top