I'm working on an app that does a tasks "A" in - (void)applicationWillEnterForeground:(UIApplication *)application
.
The app is also registered for remote notifications. In - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
the app needs to execute a task "B".
When the app is background and a notification is received the order of task execution is "A", followed by "B".
What i need to do, in case a notification is received and the app is in background, is to execute just the "B" task.
How can one accomplish this?
Thanks
It's been a month since you posted this question so I'm not sure if you still need an answer, but I solved this problem by pushing all shared "entrance logic" (as I like to call it) to applicationDidBecomeActive:
and simply store the entrance method as state in the appdelegate object. So if I come into the app from the background, then I set one flag. If I come in through a notification, I store the notification message (so I can intelligently process the notification entrance logic). If I came in through a url, then I store that url. In applicationDidBecomeActive:
I look to see which way I came in from. Here are the states that I watch for:
With all the necessary pieces of information in one place, I can intelligently decide if I want to execute the notification entrance logic, or the simple enter foreground entrance logic.
BTW, this flow chart is invaluable! http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/