JosephT
JosephT

Reputation: 865

getting local notification while the app is in background

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 ?

Upvotes: 3

Views: 6504

Answers (1)

MeloS
MeloS

Reputation: 7938

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.

Upvotes: 3

Related Questions