【问题标题】:Firebase API is not sending push notifications when using the API使用 API 时 Firebase API 不发送推送通知
【发布时间】:2016-07-20 11:12:18
【问题描述】:

我正在从 Parse 迁移到 Firebase,并且遇到了我们的 ios 应用程序的问题。 Firebase API 不会向 ios 应用发送推送通知。 这是我发送给https://fcm.googleapis.com/fcm/send的内容

{ 
 "to: "<registration token>",
 "priority": "high",
 "data": {
     "customId": "<my custom id>",
     "badge": 1,
     "sound": "cheering.caf",
    "alert": "New data is available"
  }
}

服务器返回成功

{
    "multicast_id":6917019914327105115,
    "success":1,
    "failure":0,
    "canonical_ids":0,
    "results":[{"message_id":"0:1468961966677585%f0f84693f9fd7ecd"}]
}

但是推送没有送达。 如果我使用 Firebase 仪表板发送推送,即使我直接使用 Token 定位,推送也会传递。

我看到另一个开发者在另一个 Stackoverflow 问题中抱怨 Can't send push notifications using the server API

我尝试了他们添加 "priority": "high" 的解决方案,但并没有解决问题。但它给了我一个线索:他们也在使用 dev/sandbox 推送证书。

我怀疑 Dashboard 可以使用 ios Development 证书,但 API 不能。该问题仅发生在 ios 设备上,因为 android 应用正在通过 API 获取推送。

是否有人可以使用 API 和开发证书发送推送?

【问题讨论】:

  • 我遇到了同样的问题,但在 Android 中

标签: ios firebase push-notification firebase-cloud-messaging


【解决方案1】:

Firebase 支持人员与我联系并找出了问题所在

我的推送负载缺少通知对象

{ 
 "to": "<registration token>",
 "priority": "high",
 "notification": {
    "title": "Your Title",
    "text": "Your Text"
  }
 "data": {
     "customId": "<my custom id>",
     "badge": 1,
     "sound": "cheering.caf",
    "alert": "New data is available"
  }
}

希望对其他人有所帮助

【讨论】:

【解决方案2】:

您使用 Firebase API 发送到 https://fcm.googleapis.com/fcm/send 的对象应如下所示:

{
  "notification":{
    "title":"Notification title",  //Any value
    "body":"Notification body",  //Any value
    "sound":"default", //If you want notification sound
    "click_action":"<activity_name>",  //Must be present for Android
    "icon":"fcm_push_icon"  //White icon Android resource
  },
  "data":{
    "param1":"value1",  //Any data to be retrieved in the notification callback
    "param2":"value2"
  },
    "to":"/topics/topicExample", //Topic or single device
    "priority":"high", //If not set, notification won't be delivered on completely closed iOS app
    "restricted_package_name":"" //Optional. Set for application filtering
}

如果您的问题已经解决,请不要忘记标记它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-28
    • 2016-09-26
    • 2016-11-04
    • 1970-01-01
    • 2019-03-18
    • 2018-02-28
    • 2017-02-24
    • 1970-01-01
    相关资源
    最近更新 更多