【问题标题】:How to config Firebase Push notification Message如何配置 Firebase 推送通知消息
【发布时间】:2019-04-05 08:01:34
【问题描述】:

我找到了各种示例,说明如何在 Firebase 上为 android 和 ios 配置消息 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"
        }
    }
}

}

【问题讨论】:

标签: android firebase xamarin.forms firebase-cloud-messaging


【解决方案1】:

notification 有效负载中设置"priority""sound" 对我没有帮助。这种行为非常奇怪。 我决定只使用Data 有效负载并在onMessageReceived 方法中处理background/foreground 消息并显示您的自定义通知。

在此之后,我能够显示具有最高 prioritypop-ups 和声音的通知。

详细了解 Firebase 数据消息here

【讨论】:

  • 如何处理收到消息的背景。这不仅适用于前台吗?
  • @cpiock 检查此表firebase.google.com/docs/cloud-messaging/android/…。使用Data时,前台和后台都会触发onMessageReceived
  • 这意味着通过删除通知标签我可以使用 onmessagereceived 处理我的消息?哦,听起来不错
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-06-05
    • 1970-01-01
    • 2019-08-25
    • 2018-01-21
    • 2016-12-13
    • 1970-01-01
    • 2021-09-02
    • 2020-05-09
    • 2020-07-08
    相关资源
    最近更新 更多