首页 > 解决方案 > 如何配置 Firebase 推送通知消息

问题描述

我找到了各种关于如何为 Android 和 ios 的 firebase 上的推送通知配置消息 json 的示例。但我有一个问题,并非所有推送消息都到达我的客户端应用程序。我注意到在不同的 android 版本上它以不同的方式工作。其中一些,没有收到任何消息,其中一些没有配置的铃声,其中一些只有默认铃声,有些工作正常。在客户端,我认为一切都应该没问题。我正在为此使用 xamarin 表单。我的消息 json 看起来像这样。我现在已经读到我应该删除通知标签,但它适用于较旧的机器人?

 {
"to": "/topics/MYTOPIC",
"notification": {
    "title": null,
    "body": "test",
    "sound": "de900",
    "content_available": true
},
"priority": "high",
"data": {
    "missionGuid": "",
    "eventGuid": "",
    "messageGuid": "e3ab4c34-125b-4ea7-abf7-3ee8fe1453ce",
    "ric": "199900",
    "title": null,
    "body": "test",
    "priority": "high",
    "sound": "de900"
},
"android": {
    "priority": "high",
    "notification": {
        "title": null,
        "body": "test",
        "sound": "de900",
        "content_available": true
    },
    "data": {
        "missionGuid": "",
        "eventGuid": "",
        "messageGuid": "e3ab4c34-125b-4ea7-abf7-3ee8fe1453ce",
        "ric": "199900",
        "title": null,
        "body": "test",
        "priority": "high",
        "sound": "de900"
    },
},
"apns": {
    "headers": {
        "apns-priority": 10
    },
    "payload": {
        "aps": {
            "alert": {
                "title": null,
                "body": "test"
            },
            "sound": "de900"
        }
    }
}

}

标签: androidfirebasexamarin.formsfirebase-cloud-messaging

解决方案


据我所知,设置"priority": "high"是确保通知立即发送的唯一方法。如果他们仍然无法收到任何东西,那可能是客户端的问题。

对于铃声,据说"sound": "WHATEVER"应该指定声音,但同样,由于不同的 OEM 和系统变化,发送数据消息并在收到时自己推送通知可能会更一致,但你应该知道即使这样也不能保证送达或铃声。

在某些设备上这工作正常(希望是大多数设备)这一事实表明您可能对配置进行了正确设置,您能做的最好的事情就是自己处理通知,并且可能对特定设备有特殊情况。


推荐阅读