I am attempting to do push notifications to my iOS app using FCM but am having problems with the sound. I followed this post and implemented the 'sound' key-value pair accordingly but firebase throw this error. Could anyone advice pls?
Error sending message: { Error: Invalid JSON payload received. Unknown name "sound" at 'message.notification': Cannot find field.
My JSON implementation on cloud functions as follows:
...
return admin.database().ref('/fcmToken/' + userUid).once('value', snapshot => {
const values = snapshot.val()
const fcmToken = values.fcmToken
var message = {
notification: {
body: 'New message(s)',
sound: 'default'
},
token: fcmToken
};
return admin.messaging().send(message)
.then((response) => {
return console.log('Successfully sent message:', response);
})
.catch((error) => {
return console.log('Error sending message:', error);
});
})
sound
parameter is specifically for Android only, which is probably the reason why you are encountering the invalid parameter error. But this is for when using Cloud Functions, have you tested using the REST API instead? See if it works. - AL.sound
under the Android notification object. I'm not saying it's not entirely possible. I'm just saying that it's not possible for Cloud Functions, hence I suggested test sending a payload via REST API. - AL.