getting local notification while the app is in background

孤人 提交于 2019-12-07 14:32:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!