Google FCM服务器:200,但没有通知发送到手机 [英] Google FCM Server: 200 but no notification sent to phone
问题描述
我正在通过邮递员(Postman)将FCM推送通知发送到已经安装了该应用程序的手机.我已启用推送通知,该应用程序在后台运行,并且我具有有效(已确认)的Firebase推送令牌.
I am working via Postman to send a FCM push notification to my phone that already has the app installed. I have push notifications enabled, the app is on the background, and I have a valid (confirmed) Firebase push token.
我要发布到 https://fcm.googleapis.com/fcm/send 带有标题(授权:key = APP_SERVER_KEY,内容类型:application/json),我的身体看起来像:
I'm POSTing to https://fcm.googleapis.com/fcm/send with the headers (Authorization: key=APP_SERVER_KEY, Content-Type: application/json), and my body looks like:
{ "notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to": MY_PUSH_TOKEN
}
我的身体得到以下200 OK响应:
I'm getting the following 200 OK response with body:
{
"multicast_id": MULTICAST_ID,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [{
"message_id": "0:MESSAGE_ID"
}]
}
一切正常,但是我没有收到手机通知吗?我该如何解决这个问题,有人知道我所缺少的吗?
everything looks fine, but I'm not getting a notification on my phone? How can I troubleshoot this, does anyone know what I'm missing?
推荐答案
找到了解决方案!
但是在我提供解决方案之前,这里为可能会遇到类似问题的其他人提供了一些背景知识.我能够POST并将通知发送到Android设备,并且能够通过Firebase控制台将推送发送到Android和iOS设备,所以唯一没有用的就是将推送发送到特定的iOS设备通过POST HTTP请求(相当困惑).
But before I offer the solution, here is a bit more background on the situation for others who might find themselves in a similar problem. I was able to POST and send a notification to an Android device, and I was able to send a push via the Firebase console to both Android and iOS device, so the only thing didn't work was sending the push to specifically an iOS device via a POST HTTP request (quite baffling).
我在这里找到了这个讨论: https://github.com/firebase/quickstart- ios/issues/21 .基本上对于iOS,我在请求正文中缺少两个其他参数.我需要将content_available设置为true,并将优先级设置为高.
I found this discussion here: https://github.com/firebase/quickstart-ios/issues/21. Basically for iOS, I was missing two othere parameters in the request body. I needed to set content_available to true, and priority to high.
所以看起来像这样:
{ "notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1"
},
"content_available": true,
"priority": "high",
"to": MY_PUSH_TOKEN
}
我相信github讨论中谈到了有关那些添加的请求正文参数如何允许FCM通过iOS的APNS推送的事情.
I believe the github discussion said something about how those added request body parameters allows FCM to push via APNS for iOS.
这篇关于Google FCM服务器:200,但没有通知发送到手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!