当应用程序处于终止状态时,iOS 静默推送通知不会收到

标签 ios objective-c notifications

我想在收到静默通知然后生成本地通知时根据某些条件显示显示通知。还可以在 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/

相关文章:

ios - 在 Swift 的 NSObject 子类的初始化器中调用 super.init()

ios - setCurrentPlaybackTime 的奇怪行为

objective-c - OSX - 禁用 Webview 的外部站点链接

准确时间的 Android 通知

android - 以编程方式清除短信通知

ios - UIImage方法 "drawInRect"的内存泄漏

ios - 显示当前星期几和日期

ios - 如何将 NSString 散列为 SHA512

ios - Parse SDK 不需要调用dispatch_get_main_queue(),对吧?

android - Oreo Heads up 通知 - 如何检测/拦截用户将通知刷到状态栏?