So, here's the deal ... I need a way to distinguish from what state of the application I received UILocalNotification .
There is one scenario that I do not understand for me. That is, when the application is currently running in the foreground and the user pulls out the Notification Center (iOS 5), then the application will get called applicationWillResignActive: which is quite logical, because it will not be active when the Notification Center is displayed on top of It. But I suspect that also applicationDidEnterBackground: will be called immediately after it has left with an active BUT , it is not. Therefore, when I receive UILocalNotifications, when in the Notification Center my application will try to deal with them in application:didReceiveLocalNotification: but when I click on a notification from my application that is in the Notification Center list, my application will process this notification in the same way that was when I got it at the Notification Center. Therefore, I can only process these notifications in one way, but I will need to process them in two ways.
So, how would I distinguish between these two situations:
When the application is in the foreground, and the user has disabled the Notification Center, and I receive a notification during this time
( UIApplicationState = UIApplicationStateInactive )
When the application is in the foreground, and the user turned off the Notification Center and actively selects one of the applications of my notification application from the list ( UIApplicationState =
UIApplicationStateInactive UIApplicationState =
UIApplicationStateInactive UIApplicationState =
UIApplicationStateInactive )
EDIT:
I save all my notifications with a timestamp with 00 seconds. So, inside application:didReceiveLocalNotification: I could check the current time [NSDate date] and see if there were more than 00 seconds? This would mean that it is not the iOS that triggered the notification, but the user from the notification center. Of course, this refers to the fact that notifications will actually be delivered by iOS on time. If iOS provides a notification after 01 second, my logic will break. But for the sake of this, I just made a few protocols to see when iOS provides my notifications, and judging by the conclusions from the console, notifications are actually delivered on time with millisecond accuracy (+/- 1). Of course, you cannot compare a development device connected to a computer with a realistic scenario.
2012-07-08 10:09:00.789 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running 2012-07-08 10:10:00.789 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running 2012-07-08 10:11:00.788 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running 2012-07-08 10:12:00.790 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running 2012-07-08 10:13:00.790 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running 2012-07-08 10:14:00.789 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running 2012-07-08 10:15:00.789 App[7535:707] -[AppDelegate application:didReceiveLocalNotification:] [Line 399] application:didReceiveLocalNotification: method running
source share