3

while the app is in background didReceiveLocalNotification is not called.

So I try to get the notification from didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{ 
 UILocalNotification *notification = [launchOptions  objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
//...
}

But My App is with Background Mode enable (using external accessory communication) When click on the notification, didFinishLaunchingWithOptions is not called.

Any other way to retrieve notification ?

JosephT
  • 865
  • 1
  • 11
  • 20
  • 1
    When your app is in background local notification will come automatically, `didReceiveLocalNotification` is used when your app is in foreground. – Yogesh Suthar Aug 18 '14 at 03:53

1 Answers1

3

By checking Apple's document about notifications, it says:

iOS Note: In iOS, you can determine whether an application is launched as a result of the user tapping the action button or whether the notification was delivered to the already-running application by examining the application state. In the delegate’s implementation of the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method, get the value of the applicationState property and evaluate it. If the value is UIApplicationStateInactive, the user tapped the action button; if the value is UIApplicationStateActive, the application was frontmost when it received the notification.

As far as I know, when your app is in background-running state, and there comes a local notification, you won't receive any method call, the notification will be displayed to user, but if user tap the notification and thus reactive your app, you will receive -didReceiveLocalNotification: call.

Community
  • 1
  • 1
CarmeloS
  • 7,868
  • 8
  • 56
  • 103