Assuming that I understood your problem correctly, I came across the same obstacle and could not find a super-clean solution.
So, the situation when the next method
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
and applicationState equal to UIApplicationStateInactive occurs in two cases:
- the application is in the foreground and the notification has just been launched.
- the notification was fired some time ago, the notification center is removed and the user clicked on the notification
One way to distinguish between these two cases is to check the firedate notification:
notification.fireDate.timeIntervalSinceNow < 0.5
If this expression is true, it is very likely that the first case occurred. If the expression is false, it is very likely that a second case has occurred.
This decision depends on the system providing the notification without delay, and / or the user is not fast enough to click the notification in the notification center up to 500 ms after the notification starts. I'm not sure how likely this will be. I think this is possible if the device is under some kind of processing load.
I hope there is a cleaner solution, hope someone shares it.
Srฤan Staniฤ
source share