FCM Notification in iOS doesn't play sound when received

33,429

Solution 1

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"
}

Solution 2

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)

Solution 3

    payload = {
        notification:{
            title: 'SOLO has been changed by an administrator',
            body: 'Administrator changed your SOLO schedule',
        },
        android: {
        },
        apns: {
            headers:{
                "apns-collapse-id": "solo_changed_administrator",
                "content-available": "1",
                "apns-priority": "10",
            },
            payload:{
                aps:{
                    sound: 'default',
                    badge: 12213123223
                }
            }
        },
        data:{
            type: 'type'
        }
    }

https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#ApnsConfig

Share:
33,429

Related videos on Youtube

Jr Pro
Author by

Jr Pro

Updated on July 15, 2022

Comments

  • Jr Pro
    Jr Pro almost 2 years

    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
    • Moxarth
      Moxarth almost 7 years
      i am getting notifications from fcm . now , i want to make functionality such as when i will get notification from fcm , app should play a sound file without even touching notification message . do you know how to do that ? didRecieveRemoteNotification will only get executed when user tap on notification . i want to play a sound file like alarm tune when i get the notification . please guide me through it .
  • VikasGoyal
    VikasGoyal about 7 years
    I am having the same structure on server but still on some devices sound file is not playing when app is in background.
  • Moxarth
    Moxarth almost 7 years
    i am getting notifications from fcm . now , i want to make functionality such as when i will get notification from fcm , app should play a sound file without even touching notification message . do you know how to do that ? didRecieveRemoteNotification will only get executed when user tap on notification . i want to play a sound file like alarm tune when i get the notification . please guide me through it .
  • Joe Sleiman
    Joe Sleiman almost 7 years
    where should this json file exist ? because i'm testing the notification via ui firebase.com , so how can i send this payload with sound?
  • JVG
    JVG almost 6 years
    Good call - I haven't been able to find any info on getting notification sounds to work in IOS anywhere, didn't realise it was part of the APNS object! Cheers for this.
  • Cyril
    Cyril over 5 years
    Thank you, it worked for me. Would you please provide the source of your answer? Thank you.
  • Works for a Living
    Works for a Living almost 5 years
    @DuncanJones, actually, your answer didn't work for me with iOS 12.1 but putting sound:'default' in the non-device-specifc notification object ultimately worked for me.
  • user924
    user924 almost 5 years
    but it takes only two arguments (title and body) if you do it without json: Message.builder() .setNotification(new Notification( "$GOOG up 1.43% on the day", "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")) firebase.google.com/docs/cloud-messaging/ios/topic-messaging
  • Manu Eidenberger
    Manu Eidenberger over 4 years
    Attention, this is only true if you use legacy api, and not http v1 api. see this page: firebase.google.com/docs/cloud-messaging/migrate-v1