无法使用服务器API发送推送通知

我正在使用新的Firebase平台。 我试图得到我的应用程序服务器发送的推送通知,并将其发送到我的iPhone。

我的安装程序工作在手动将消息发送到网站上的Firebase通知区域,但是当我尝试使用POST将消息发送到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网站直接发送到此设备,则可以正常工作,但上述表单不适用。 不知道该从哪里出发!

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

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

如果API向您返回message_id则意味着您的消息已被正确接受,并且最终将传递给设备。

  • 在Android上,消息尽快传送(假设设备连接当然)。

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

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

我发现message字段是必需的,以及priority字段用POST发送消息。

Firebase控制台中不需要message (并标记为可选)。

我解决了没有priority请求正文中添加notification标记。

这里是一个概述: 在这里输入图像说明