Ad

Custom Push Notifications Not Receiving Using Firebase

- 1 answer

I have implemented an app with custom notification using firebase. I am able to receive custom notifications using device token from the pusher, pushtry, But if I send the same payload using FCM ID from postman then not receiving the notification.

I have tried other payloads also but just receiving the default notification and sometimes only sound for some payloads, but not getting custom one.

I am using the payloads like this for pusher and pushtry: (received proper notifications)

{ 
"aps":{ 
"alert":"dasdas",
"badge":1,
"sound":"default",
"category":"CustomSamplePush",
"mutable-content":"1"
},
"urlImageString":"https://res.cloudinary.com/demo/image/upload/sample.jpg"
}

the same payload not working for firebase

Is there any proper payload for that and is there any need to do changes from my ios code?

thanks in advance.

Ad

Answer

Your payload should be like:

{
    "to": "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
    "notification": {
        "body": "dasdas",
        "title": "Portugal vs. Denmark",
        "icon": "myicon"
    },
    "data": {
        "Nick": "Mario",
        "Room": "PortugalVSDenmark"
    }
}

Having all data under aps does not trigger any notification in iOS even though Firebase returns a successful request because the forwarded APNS payload is not correct. Besides the proper way should be to follow the GCM or FCM payload recommendations, which is to use both notification for the notification message and data for custom key/value pairs.

When FCM Send data to APNS it convert it into APNs payload. It set values of notification in aps tag i.e.

{
    "aps" : {
        "alert" : {
            "title" : "Portugal vs. Denmark",
            "body" : "Portugal vs. Denmark",
        }
    },
    "Nick" : "Mario",
    "Room" : "PortugalVSDenmark"
}
Ad
source: stackoverflow.com
Ad