如何从Rest API发送推送通知

时间:2018-07-24 09:00:58

标签: ios rest firebase firebase-cloud-messaging

我已经在Firebase中创建了我的应用程序,并配置了云消息传递功能。 当我从Firebase控制台发送通知时,设备会收到通知,但是如果我尝试通过Rest API(使用PostMan)进行发送。 然后通知未到达设备,但响应显示为成功。

这是我的PostMan请求

  

URI-the JLS

     

标题:Content-Type:应用程序/ json授权:key = MY_SERVER_KEY

     

正文:{“ data”:{“ title”:“ Firebase”,“ detail”:“我是firebase”},   “至”:“我的FCM令牌在这里”}

     

响应:{       “ multicast_id”:7834540847388366233,       “成功”:1,       “失败”:0,       “ canonical_ids”:0,       “结果”:[           {               “ message_id”:“ 0:1532422122326299%ebf5f25ef9fd7ecd”           }       ]}

我已经搜索过,看来文档中提到的方式与我遵循的方式相同 谁能告诉我为什么它不起作用? 谢谢

1 个答案:

答案 0 :(得分:1)

I am posting here so as to guide others. As per the guidance of @rv7284, We need to send the data in notification key rather any other key.

So While requesting the body should look like this, Other request parameter like header and all will be same as mentioned in the question.

{ "notification": {
 "title": "Firebase",
 "detail": "I am firebase"
},
 "to" : "YOUR FCM TOKEN"
}