PDA

View Full Version : UILocalNotification issue




themoonisdown09
Jul 6, 2010, 01:39 PM
I have an app using local notifications with iOS 4. If the user opens my application and schedules a local notification, then exits, the application is still running in the background (I know it's not really running in the background, but you know what I mean).

When the user then receives the local notification alert, clicking on the action button launches my application, but does not fire the application:didFinishLaunchingWithOptions: method. It simply only calls the application:didReceiveLocalNotification: method. This is a problem for me since I need to get data about the notification.

I'm 100% positive that the method name is spelled correctly because it does get called once the application has been terminating by closing it from the multi-tasking window. It also gets called the first time the application is launched.

I'm just wondering if I'm missing something or what. I really need that local notification data! Thanks in advance.



themoonisdown09
Jul 6, 2010, 02:50 PM
I just realized that I can get the userInfo dictionary from the passed UILocalNotification object in the application:didReceiveLocalNotification: method. That takes care of 50% of my problem. Now, I just need to know if the user pressed the action button or not in the alert.

Again, once the application is running, the application:didFinishLaunchingWithOptions: method is not being fired. I checked Apple's documentation (http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFinishLaunchingWithOptions:) on this method and it should be firing.

dejo
Jul 6, 2010, 03:45 PM
I checked Apple's documentation (http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFinishLaunchingWithOptions:) on this method and it should be firing.
Not meaning this to be flippant but: what gives you that idea?

I think you are probably wanting to be looking into applicationDidBecomeActive: instead.

themoonisdown09
Jul 6, 2010, 04:00 PM
Not meaning this to be flippant but: what gives you that idea?

I think you are probably wanting to be looking into applicationDidBecomeActive: instead.

I got the idea from this in Apple's documentation (http://developer.apple.com/iphone/library/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html) on UILocalNotification:


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.


Maybe I could use the applicationDidBecomeActive: method instead, but it still doesn't help me figure out if the action button was pressed or the user just launched the application by clicking the app icon.

Maybe explaining what I'm trying to accomplish might help. If the user has the application open and the app receives a local notification, I want an alert to be displayed. The reason being is that this is a reminder application. If the user has the application closed and then clicks the action button in the alert, the application should open and not display an additional alert.

I'm having a problem because I have the logic to display the alert in the application:didReceiveLocalNotification: method and this is called either when the user clicks the action button or has the application in the foreground.

themoonisdown09
Jul 7, 2010, 08:24 AM
I finally solved my problem. I ended up doing a conditional statement in the application:didReceiveLocalNotification: method that checks to see if the current state of the application is UIApplicationStateActive. If it is, then I show the alert message. If it's not, I don't bother showing the alert message since the local notification presented one to the user.

I'm sure this doesn't make sense, but I'm just happy that I figured it out.