Firebase云消息传递声音错误

use*_*557 1 firebase firebase-cloud-messaging

我正在尝试使用firebase api发送通知,如果我在通知JSON对象中只有"title"和"body",则通知会成功发送.但是,如果我向通知对象添加"声音":"默认",如文档中所述,我收到以下错误:

"收到无效的JSON有效负载.未知名称\"声音\"在'message.notification':找不到字段."

我的JSON对象如下:

{"message":{"token": token, "notification":{"title":"Test", "body":"Test message from server", "sound":"default"}}}
Run Code Online (Sandbox Code Playgroud)

Bob*_*der 17

messageJSON中的外观表明您正在使用HTTP v1 API.您链接的文档适用于旧版API.

用于为Android和iOS设备发送声音通知的HTTP v1 API JSON应该是:

{
    "message": {
        "token": "your-token-value",
        "notification": {
            "title": "Test",
            "body": "Test message from server"
        },
        "android": {
            "notification": {
                "sound": "default"
            }
        },
        "apns": {
            "payload": {
                "aps": {
                    "sound": "default"
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @cicaletto79:我在查看 [this example](https://firebase.google.com/docs/cloud-messaging/admin/send-messages#apns_specific_fields) 后更新了我的答案。 (2认同)