Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google FCM Server: 200 but no notification sent to phone

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.

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
}

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?

like image 355
Ke Cheng Avatar asked Dec 15 '22 03:12

Ke Cheng


1 Answers

Found the solution!

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).

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.

so it looked like this:

{
    "notification": {
        "title": "Portugal vs. Denmark",
        "body": "5 to 1"
    },
    "content_available": true,
    "priority": "high",
    "to": MY_PUSH_TOKEN
}

I believe the github discussion said something about how those added request body parameters allows FCM to push via APNS for iOS.

like image 142
Ke Cheng Avatar answered Dec 16 '22 17:12

Ke Cheng