application: didReceiveRemoteNotification: fetchCompletionHandler:
不同于
application: didReceiveRemoteNotification:
如何?来自文档:
与 application:didReceiveRemoteNotification: 方法不同,它是
仅当您的应用程序运行时调用,系统调用此方法
无论您的应用程序的状态如何。您的应用是否被暂停
运行时,系统唤醒或启动您的应用程序并将其放入
调用该方法之前的后台运行状态。如果用户打开
您的应用程序从系统显示的警报中,系统调用此方法
再次以便您知道用户选择了哪个通知。
我的困难是:我想知道该方法是否是由用户点击通知中心的系统显示警报或唤醒设备的静默推送通知来调用的。目前,据我所知,没有明显的方法来区分。
- (BOOL)application: didFinishLaunchingWithOptions:
追踪启动选项上面的方法不是一个解决方案,因为它仅在应用程序挂起/不在后台运行时才会被调用。如果它在后台运行,则不会被调用。
Apple 文档有点令人困惑
application: didReceiveRemoteNotification: fetchCompletionHandler:
如果您的应用程序支持远程通知后台模式(即您正在执行BackgroundFetch),则使用。
application: didReceiveRemoteNotification:
当操作系统收到 RemoteNotification 并且应用程序正在运行(在后台/挂起或在前台)时调用。
您可以检查 UIApplicationState 以查看应用程序是否被用户带到前台(点击通知)或在通知到来时已经在运行。
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [application applicationState];
// user tapped notification while app was in background
if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) {
// go to screen relevant to Notification content
} else {
// App is in UIApplicationStateActive (running in foreground)
// perhaps show an UIAlertView
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)