【问题标题】:Notification Service Extension does not handle data messages when using Firebase Data Message使用 Firebase 数据消息时,通知服务扩展不处理数据消息
【发布时间】:2018-11-06 09:03:34
【问题描述】:

该应用同时在 iOS 和 Android 上运行,为了让此通知在两个平台上都能正常工作,我从通知 json 有效负载中删除了 notification 字段。但是现在 iOS 在后台不处理这个通知。

这个适用于 iOS,但它有 notification 字段,我确实想要。

{
  "registration_ids": [
        "...",
        "..."
    ],
  "priority": "high",
  "notification": {
    "body": "Notification Body.",
    "title": "Notification Title"
  },
  "data": {
    "userId": "11111",
    "badge": 10
  }
}

这个可以在 android 中运行,但在后台运行在 iOS 上:

{
  "registration_ids": [
        "...",
        "..."
    ],
  "mutable_content": true,
  "content_available": true,
  "data": {
    "click_action": "AndroidIntent"
    "message": "Notification Body",
    "myDataField": "11",
    "location": "3",
    "imageurl": "http://image.com/13fd.png"
  }
}

底部的甚至没有进入我的通知服务扩展。如何确保调用通知服务扩展而不在我的 json 中添加 notification 字段?

【问题讨论】:

  • 这可能会有所帮助:stackoverflow.com/questions/40807397/…
  • 上面的payload中带有“notification”键的是否进入了Notification Service Extension?我也有同样的问题。我的通知服务没有被调用,这就是我无法通过 FCM 在通知上创建缩略图的原因。

标签: ios swift firebase apple-push-notifications firebase-cloud-messaging


【解决方案1】:

我也有同样的想法。我正在考虑从firebase 接收数据并推送本地通知,其中包含自定义标题和正文以及通知服务扩展。通过在appDelegate 中实现didReceiveRemoteNotification userInfo: 以接收userInfo,这个想法在前台运行良好。

但是通过启用content_available,它在后台模式下不起作用。您使用与firebase docs. 相关的APN 服务器 而不是Fcm 服务器 发送通知我建议查看content_availablemutable_content

【讨论】:

    【解决方案2】:

    删除content_available,因为这是处理静默通知的属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-23
      • 2012-11-25
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 2015-03-07
      相关资源
      最近更新 更多