无法使用服务器API

时间:2016-05-19 19:28:23

标签: ios firebase firebase-cloud-messaging

我正在使用新的Firebase平台。我试图通过我的应用服务器发送推送通知并发送到我的iPhone。

我在设置工作的地方手动发送消息与网站上的Firebase通知区域,但是当我尝试将消息发送到https://fcm.googleapis.com/fcm/send时,我没有收到任何消息传递给设备。

我发送以下内容(使用auth标头)

{ "notification": {
    "title": "Portugal vs. Denmark",
    "text": "5 to 1"
  },
  "to" : "<registration token>"
  }

我收到了来自POST的200个回复,其中包含以下内容:

    {
  "multicast_id": 5511974093763495964,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    {
      "message_id": "0:1463685441784359%3ad254b53ad254b5"
    }
  ]
}

如果我尝试直接通过Firebase网站发送到此设备,它可以正常工作,但上面的表格帖子没有。不知道从哪里开始!

4 个答案:

答案 0 :(得分:32)

在iOS上,priority字段似乎是强制性的。

{   
  "to": "cHPpZ_s14EA:APA91bG56znW...",
  "priority": "high",
  "notification" : {
    "body" : "hello!",
    "title": "afruz",
    "sound": "default"
  }
} 

答案 1 :(得分:1)

如果API返回message_id,则表示您的邮件已被正确接受,并且最终将传递给设备。

  • 在Android上,邮件会尽快发送(假设设备已经连接)。

  • 在Apple设备上,如果应用程序已关闭或在后台运行,通知将通过Apple基础架构发送,并可能因Apple文档而相应延迟。

要减少发送到Apple设备的优先级消息的延迟,您可以使用priority参数。 更多详情:https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message

答案 2 :(得分:1)

我找到了所需的message字段,以及priority字段来发送带有POST的邮件。

Firebase控制台中不需要

message(并标记为可选)。

答案 3 :(得分:0)

我决定在没有notification的请求正文中添加priority标记。

这是一个回顾: enter image description here