请帮忙。
我对firebase的请求如下:
curl https://fcm.googleapis.com/fcm/send -X POST \
--header "Authorization: key=my-api-key" \
--Header "Content-Type: application/json" \
-d '
{
"to": "firebase-instance-id"
"notification":{
"title":"New Notification!",
"body":"Test"
},
"priority":10
}'
我得到回应:
{
"multicast_id":7748668110190879774,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{
"message_id":"0:1505463398077072%3f95c2ka3f95c2ca"
}]
}
但我看到Firebase控制台列表中没有添加通知,也没有在手机中看到。有什么建议?也许我应该更改一些设置,以便通过curl从我的服务器发送通知?提前谢谢。
答案 0 :(得分:0)
Firebase很奇怪,根据他们的文档,您发送了正确的JSON内容,但Apple's documentation需要略微修改的格式,特别是消息周围的“aps”包装。
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5
}
尝试将Apple的JSON格式添加到当前的JSON有效内容中,并查看其响应方式。从那里,您可以调整有效负载,以确保它适用于Android(这是Firebase的文档)和iOS。
答案 1 :(得分:0)
我认为您的FCM有效负载格式不正确。它缺少逗号("firebase-instance-id"
),优先级值应为high
。
'{
"to": "firebase-instance-id",
"notification":{
"title":"New Notification!",
"body":"Test"
},
"priority":"high"
}'
与Chris'相反。回答,不要使用APNs有效载荷格式,因为您首先要从FCM发送它。