我想在收到静默通知然后生成本地通知时根据某些条件显示显示通知。还可以在 Xcode 中启用后台模式并启用远程通知和后台获取。 对于像这样的静默通知消息格式 -
{
"message":{
"token":"iosdevicetoken",
"apns": {
"payload": {
"aps": {
"content-available": 1,
"category": "GENERAL",
"priority": "high",
"token": "randomkey",
"customkey": "abcs"
}
}
}
}
}
但是当应用程序处于终止状态(从后台状态滑动)时,不会调用下面的委托(delegate)方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
}
最佳答案
这是故意的。来自 documentation对于 application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
:
In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
(强调)
iOS 将用户从任务切换器中删除应用程序视为他们不希望应用程序再在后台运行的信号。因此,iOS 不会在后台重新启动该应用程序,除非用户明确重新启动该应用程序。
关于当应用程序处于终止状态时,iOS 静默推送通知不会收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54984636/