仅当应用程序在后台时才调用静默通知回调方法

iDi*_*lip 1 iphone notifications apple-push-notifications ios

我注册了远程通知并且它工作得很好。现在我正在实施无提示通知。为此,我启用了后台远程通知和应用程序从网络下载内容。

并发送,

{"aps": {"content-available": 1}}
Run Code Online (Sandbox Code Playgroud)

它调用以下回调方法,但仅当应用程序处于后台时:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
Run Code Online (Sandbox Code Playgroud)

在这种方法中,我在从服务器下载一些数据后触发本地通知。但是当应用程序不在后台时,此方法根本不会调用。

在关于Push Notification 的Apple 文档中,他们说:

“当无提示通知到达时,iOS 会在后台唤醒您的应用程序,以便您可以从服务器获取新数据或进行后台信息处理。”

理想情况下,静默远程通知应该在后台唤醒我的应用程序,并且本地通知应该可以工作。

有什么想法吗?

iDi*_*lip 5

在阅读了大量苹果文档后,我发现如果用户强制退出应用程序,该方法 (didReceiveRemoteNotification: fetchCompletionHandler) 将不会被调用。

正如所写,(链接)但是,如果用户强制退出,系统不会自动启动您的应用程序。在这种情况下,用户必须重新启动您的应用程序或重新启动设备,然后系统才会尝试再次自动启动您的应用程序。