Firebase云消息传递 - 如何向APN添加声音

时间:2018-04-25 22:04:16

标签: firebase audio apple-push-notifications firebase-cloud-messaging

使用HTTP v1 API向iOS设备发送APN时,Apple documentation表示如果apns-priority设置为10,则

Notifications with this priority must trigger an alert, sound, or badge on the target device

documentation at Firebase似乎建议添加到apns JSON对象:

我只在使用JSON POST中的以下内容设置优先级 时才成功:

"apns": {
            "headers": {
                "apns-priority": "10"
            }
        },

当我按照文档建议发布以下内容时:

...
"apns": {
            "headers": {
                "apns-priority": "10"
            },
            "payload": {
                "sound": "default"
            }
        },
...

400 - Bad Request从FCM服务器返回。如果我排除payload json部分,则POST工作。

还尝试了以下内容:

...
"apns": {
            "headers": {
                "apns-priority": "10"
            },
            "sound": "default"
...

仍然收到400 - 错误请求

  

如何在SDK API JSON POST中的APN上设置声音?默认声音就足够了。

2 个答案:

答案 0 :(得分:1)

声音对象必须是aps对象的一部分:

...
"apns": {
   "headers": {
       "apns-priority": "10"
    },
    "payload": {
        "aps": {
            "sound": "default"
        }
    }
 },
...

答案 1 :(得分:0)

根据您的JSON,您似乎正在使用HTTP v1 API。

“apns”特定字典描述为here

例如,为了播放默认声音:

...
"apns": {
  "headers": {
    "apns-priority":"10"
  },
  "payload": {
    "sound":"default"
  },
},
...