UILocalNotification issue

Discussion in 'iPhone/iPad Programming' started by themoonisdown09, Jul 6, 2010.

  1. macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #1
    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.
     
  2. thread starter macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #2
    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 on this method and it should be firing.
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Not meaning this to be flippant but: what gives you that idea?

    I think you are probably wanting to be looking into applicationDidBecomeActive: instead.
     
  4. thread starter macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #4
    I got the idea from this in Apple's documentation on UILocalNotification:

    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.
     
  5. thread starter macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #5
    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.
     

Share This Page