问题
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 ?
回答1:
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.
来源:https://stackoverflow.com/questions/25356064/getting-local-notification-while-the-app-is-in-background