2
votes

I am trying to set the default sound for a push notification sent and have the following message object to pass through.

var message = {
      notification: {
        title: "X",
        body: "X",
        sound: 'default'
      }          
      token: fcmToken
 };

I continue, however, to receive the following error in my cloud function log:

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

I've tried placing the sound property under the notification object, apns-payload-aps object, and cannot seem to locate documentation on the correct syntax to activate the default sound on iOS.

Any help is appreciated.

2

2 Answers

4
votes

"sound" is not a valid key for the "notification" object in the message's structure. "sound" is a platform specific key that you have to set under either "android" or "apns" object.

{
    notification: {
        title: "X",
        body: "X"
    },
    apns:{
        payload: {
            aps: {
                sound: "default"
            }
        }
    }
    token: fcmToken
}

Consult this doc for more info

0
votes

insane, but for me, some reason in appdelegate the window variable was deleted and that resulted into this issue..

adding it back, sound works correctly now...