我知道很多地方都涵盖了这一点,但我无法弄清楚。我使用 Urban Airship 来推送通知。一切似乎都很好,除了当我的应用程序在后台时 - didReceiveRemoteNotification
没有被调用。它在前台工作 - 我能够正确处理消息。如果从通知中心点击消息,我可以从启动选项获取消息。但是在后台时,它发送的消息 - iOS 显示警报 - didReceiveRemoteNotification
未被调用。当我点击我的应用程序图标(不是从通知中心内)时,该应用程序出现在前台,我不知道通知是否存在。有什么想法吗?
最佳答案
application:didReceiveRemoteNotification:
仅当您将值为 1
的 content-available
键添加到通知负载中时,才会在后台调用。
如果是 Urban Airship,您可以在设置选项卡下发送测试推送。
推送通知的示例负载:
{
"aps": {
"alert": "aaaa",
"badge": "+1",
"content-available": "1"
},
"device_tokens": [
"86BA71E361B849E8312A7B943BA6B26A74AB436381CF3FEE3CD9EB436A12A292"
]
}
Apple 在他的文档中明确提到....
For a push notification to trigger a download operation, the notification’s payload must include the content-available key with its value set to 1. When that key is present, the system wakes the app in the background (or launches it into the background) and calls the app delegate’s application:didReceiveRemoteNotification:fetchCompletionHandler: method. Your implementation of that method should download the relevant content and integrate it into your app. https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
关于ios - 在后台接收推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14616261/