ios - 在后台接收推送通知

标签 ios xamarin.ios push-notification apple-push-notifications

我知道很多地方都涵盖了这一点,但我无法弄清楚。我使用 Urban Airship 来推送通知。一切似乎都很好,除了当我的应用程序在后台时 - didReceiveRemoteNotification 没有被调用。它在前台工作 - 我能够正确处理消息。如果从通知中心点击消息,我可以从启动选项获取消息。但是在后台时,它发送的消息 - iOS 显示警报 - didReceiveRemoteNotification 未被调用。当我点击我的应用程序图标(不是从通知中心内)时,该应用程序出现在前台,我不知道通知是否存在。有什么想法吗?

最佳答案

application:didReceiveRemoteNotification: 仅当您将值为 1content-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/

相关文章:

c# - 如何在 Xamarin.Android 和 Xamarin.iOS 上使用 dllmap?

ios - 从 PWA 向 iOS 发送推送通知

android - 限制 android GCM 中的 collapse_key 计数。第2部分

android - 如何通过点击推送消息通知来判断应用程序已启动

iOS 推送通知 - didReceiveRemoteNotification :fetchCompletionHandler: never called in foreground

objective-c - 是否可以在实例化对象之前检查 Storyboard中是否存在标识符?

SQLite.net 数据库与 Xamarin.Forms 应用程序

ios - 奇怪的 Xamarin.iOS 错误仅在启用调试时出现(即席/发布版本)

ios - 从 SWIFT 中的 API 缓存 JSON 的最佳方法?

ios - 更改 UISwitch 边框厚度?