Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging sound error

I'm trying to send a notification using firebase api and the notification is sent successfully if I only have "title" and "body" in the notification JSON object. However, if I add "sound":"default" to the notification object, as described in the documentation, I get the following error:

"Invalid JSON payload received. Unknown name \"sound\" at 'message.notification': Cannot find field."

My JSON object is as follows:

{"message":{"token": token, "notification":{"title":"Test", "body":"Test message from server", "sound":"default"}}}
like image 420
user3669557 Avatar asked Feb 08 '18 16:02

user3669557


1 Answers

The appearance of message in your JSON indicates you are using the HTTP v1 API. The documentation you linked is for the legacy API.

The HTTP v1 API JSON to send a notification with sound for Android and iOS devices should be:

{
    "message": {
        "token": "your-token-value",
        "notification": {
            "title": "Test",
            "body": "Test message from server"
        },
        "android": {
            "notification": {
                "sound": "default"
            }
        },
        "apns": {
            "payload": {
                "aps": {
                    "sound": "default"
                }
            }
        }
    }
}
like image 155
Bob Snyder Avatar answered Nov 13 '22 04:11

Bob Snyder