Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM Notification in iOS doesn't play sound when received

I am using Firebase push notifications in my iOS Application. Although I am able to send the notification by sending below payload, it doesn't play a sound when received.

{     "to": "myToken",     "notification": {         "body": "test",         "title": "test"     },     "priority": "high"     "sound": "default" } 

If I send the test message from console, it works well and plays notification sound.
Note:

  1. My Authorization code is correct
  2. I am sending http request to https://fcm.googleapis.com/fcm/send
  3. I have tested it on IPhone 4 , IPhone 6 and IPhone 6S, All recieve notifications without sound
like image 301
Jr Pro Avatar asked Sep 05 '16 17:09

Jr Pro


People also ask

Does firebase notification work on iOS?

For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.

Can push notifications have sound?

On Android devices, it is possible to choose individual push notification sounds.

How do I test FCM push notifications?

Send a test notification messageOpen the Notifications composer and select New notification. Enter the message text. Select Send test message. In the field labeled Add an FCM registration token, enter the registration token you obtained in a previous section of this guide.

Why is FCM delayed?

This could be caused by the unrealistic heartbeat intervals in Firebase Cloud Messaging. FCM works by maintaining an idle socket connection from an Android device to Google's servers.


2 Answers

your JSON "sound" : "default" should be inside the "notification" key not in the root of the JSON. This JSON should work.

{     "to": "myToken",     "notification": {          "body": "test",          "title": "test",          "sound": "default"     },     "priority": "high" } 
like image 83
kaitosenpai Avatar answered Sep 24 '22 22:09

kaitosenpai


When using the FCM admin SDK, you have to specify sounds separately for Android and Apple devices:

let message = {     notification: {         'body': 'This is the message the user sees',     },     data: {         'param1': 'specify some extra data here',     },     // Apple specific settings     apns: {         headers: {             'apns-priority': '10',         },         payload: {             aps: {                 sound: 'default',             }         },     },     android: {       priority: 'high',       notification: {           sound: 'default',       }     },     token: 'target FCM token goes here', }; 

(Note: I've only tested the Apple settings thus far)

like image 30
Duncan Jones Avatar answered Sep 21 '22 22:09

Duncan Jones