如果应用程序被终止,应用程序在后台时收到的远程通知不会命中 "didReceiveRemoteNotification - fetchCompletionHandler" 方法?

Remote Notification received while app is background doesn't hit "didReceiveRemoteNotification - fetchCompletionHandler" method if app is killed?

我们已经实施了以下方法来接收远程通知并启用了 "Background Fetch and Remote Notification under Capabilities of a project"。即使应用程序处于前台或后台,方法也会命中。但是"If app is killed, received notification in background then following method doesn't get called"。如何解决这个问题?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Some storage code
}

提前感谢您的帮助!

间接终止应用程序会禁用推送通知。

这是因为如果用户关闭应用程序,the OS will not relaunch it除非用户点击主屏幕上的应用程序图标。

这很不幸,因为大多数用户不知道关闭应用程序(这很有趣!)会产生这些恼人的附带影响。

这是来自 Apple 的 "App Programming Guide for iOS":

In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system.

当应用被终止时。推送通知将不支持。因为你的app已经不是运行了。因此,无法收到推送通知。

如果应用未激活,则不会调用此方法。相反,如果用户从通知启动应用程序,应用程序将在 didFinishLaunchingWithOptions 中有一个有效负载,您可以在这里处理通知。

如果应用未从通知中打开,您将不会收到此信息。

你到底想做什么?您可以让应用请求后台时间,并根据需要执行代码。