dtmland
dtmland

Reputation: 2216

UILocalNotification handle when opened via App icon?

I'm working with UILocalNotifications for the first time. Mostly working with repeating notifications. Most all makes sense, except one thing.

Apple Documentation states several cases for handling local notifications when they fire.

First, a case for when the user "taps the notification" when outside of the App:

If the notification is an alert and the user taps the action button (or, if the device is locked, drags open the action slider), the application is launched. In the application:didFinishLaunchingWithOptions: method the application delegate can obtain the UILocalNotification object from the passed-in options dictionary by using the UIApplicationLaunchOptionsLocalNotificationKey key. The delegate can inspect the properties of the notification and, if the notification includes custom data in its userInfo dictionary, it can access that data and process it accordingly.

It also states a case for what happens when the user is inside the App:

If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.

In both of those cases the developer can access the uilocalnotification and then decide what to do with it. However, in a third case - when the user, outside of the App, sees and ignores the notification and then later launches the App, no method is called that allows the application to know which notifications have previously fired?

At first I thought that this statement was describing that behavior, but now I am not sure:

On the other hand, if the local notification only badges the application icon, and the user in response launches the application, the application:didFinishLaunchingWithOptions: method is invoked, but no UILocalNotification object is included in the options dictionary.

How can I handle the third case? How can I know which local notifications have fired? Do I need to iterate through my list and check all their times myself? Is there a better way to accomplish this?

Upvotes: 1

Views: 1095

Answers (1)

J2theC
J2theC

Reputation: 4452

You need to keep track of what is happening with your notifications. What I mean with this is that, because the notification has fired, and the user didn't launch the app because of a notification nor was your app running at the time of the notification, you need to check your sources to verify if a previously scheduled notification fired date has already passed.

Upvotes: 0

Related Questions