iOS中的FCM通知在收到时无法播放声音

我在iOS应用程序中使用Firebase推送通知。 虽然我能够通过发送下面的有效负载来发送通知,但它在收到时不会发出声音。

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

如果我从控制台发送测试消息,它运行良好并播放通知声音。
注意

  1. 我的授权码是正确的
  2. 我正在向https://fcm.googleapis.com/fcm/send发送http请求
  3. 我在IPhone 4,IPhone 6和IPhone 6S上进行了测试,All收到没有声音的通知

你的JSON "sound" : "default"应该在"notification"键里面而不是在JSON的根目录中。 这个JSON应该可行。

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

使用FCM管理SDK时 ,您必须分别为Android和Apple设备指定声音:

 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', }; 

(注意:到目前为止我只测试了Apple设置)

  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