【问题标题】:Firebase Cloud Messaging sound errorFirebase 云消息传递声音错误
【发布时间】:2018-02-08 16:29:00
【问题描述】:

我正在尝试使用 firebase api 发送通知,如果通知 JSON 对象中只有“标题”和“正文”,则通知发送成功。但是,如果我将“声音”:“默认”添加到通知对象,如documentation 中所述,我会收到以下错误:

“收到无效的 JSON 有效负载。'message.notification' 中的未知名称 \"sound\": 找不到字段。”

我的 JSON 对象如下:

{"message":{"token": token, "notification":{"title":"Test", "body":"Test message from server", "sound":"default"}}}

【问题讨论】:

    标签: firebase firebase-cloud-messaging


    【解决方案1】:

    在您的 JSON 中出现message 表示您正在使用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"
                    }
                }
            }
        }
    }
    

    【讨论】:

    • 我有同样的问题,如果我使用这个结构,我得到了这个错误。 Apple Push Notification Service 的负载必须包含一个 [aps] 键。
    • @cicaletto79:我在查看this example 后更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多