title: iOS Handle notifications after starting app from not-running state
body: <p>I've been trying to handle receiving notifications in my app, but its not really working out.</p>
  
  <p>When I use <code>didReceiveLocalNotification:(UILocalNotification *)notification</code>. I can receive and use the notification that is used to enter the app, without any problems</p>
  
  <p>However, this function is only fired when the app is already <strong>running</strong> (active, inactive, background, and possibly suspended, but I haven't tried that yet).</p>
  
  <p>Now, there is this function <code>didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code> where you can use <code>[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]</code> which would return a UILocalNotification.</p>
  
  <p>However, when you launch the app from <strong>not-running</strong> state, this event is not fired. The LocalNotification then opens the app, but I can not use it in any way.</p>
  
  <p>Now, my question is: <strong>How can I make it work, so I can receive and process notifications when starting the app, from a notification, when the app is in not-running state?</strong> Is there perhaps something I'm doing wrong here?</p>
  
  <p>Here is a bit of sample code from my app:</p>
  
  <p>First, the <code>didFinishLaunchingWithOptions</code> function, which, unfortunatly does not work. The function <code>[sharedLocalNotificationsInstance processNotification:notification]</code> is never launched...</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
  
  LocalNotificationsController *sharedLocalNotificationsInstance = [LocalNotificationsController sharedLocalNotificationsInstance];
  [sharedLocalNotificationsInstance checkNotifications];
  
  UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
  if ( notification != nil ) {
  
      // Process the received notification
      [sharedLocalNotificationsInstance processNotification:notification];
  
      application.applicationIconBadgeNumber = 0;
  }
  
  return YES;
  }
  </code></pre>
  
  <p>And a second piece of code: The didReceiveLocalNotification function, which works perfectly: I receive the notification, and [sharedLocalNotificationsInstance processNotification:notification] works perfectly.</p>
  
  <pre><code>- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
  
  // Used when the application launches from a notification
  LocalNotificationsController *sharedLocalNotificationsInstance = [LocalNotificationsController sharedLocalNotificationsInstance];
  
  // Process the received notification
  [sharedLocalNotificationsInstance processNotification:notification];
  }
  </code></pre>