-->

FCM Notification in iOS doesn't play sound whe

2020-02-10 14:51发布

问题:

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

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


回答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)



回答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