iOS 未收到通过 API 发送的 Firebase 推送通知 [英] iOS not receiving Firebase Push Notification sent through the API

查看:47
本文介绍了iOS 未收到通过 API 发送的 Firebase 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google 的 Firebase Cloud Messaging 向我的 iOS 和 Android 应用程序发送推送通知.通过 Cloud Messaging 控制台发送的推送通知按预期工作,但是当我通过 API 发送推送通知时,iOS 应用程序仅在前台接收它.在 Android 上,它工作正常(在前台和后台).

I'm using Google's Firebase Cloud Messaging to send push-notifications to my iOS and Android applications. The push-notifications sent through the Cloud Messaging console work just as intended, however when I send a push-notification through the API, the iOS application only receives it when in foreground. On Android, it is working correctly (both in foreground and background).

阅读文档后,iOS 系统会按预期将通知"对象传输到系统托盘,显示正文"消息.但是,这不起作用.

Reading the documentation, the iOS system would then transfer the "notification" object to the system tray, as intended, showing the "body" message. However, this is not working.

这是我发送的 JSON 的内容:

Here's the content of the JSON I'm sending:

{
    "notification":
        {
            "body": "This a test notification"
        },
        "to":"eQ5tiy0cMZ8:APA91bE4CCjDXEJxEIRxKY18pXMMGUBqY1OKJFhVbR-pNhvQjJuhPcc7pXa..."
}

最近是否有人在使用 Firebase Cloud Messaging 时遇到过类似问题?谢谢.

Did anyone have similar problems using Firebase Cloud Messaging recently? Thank you.

推荐答案

由于这个答案,我设法解决了这个问题:https://stackoverflow.com/a/37550067/516338

I managed to fix the problem thanks to this answer: https://stackoverflow.com/a/37550067/516338

基本上,虽然不在文档中,但您必须在 iOS 上将优先级"字段设置为高",如下所示:

Basically, although NOT in the documents, you have to set the "priority" field to "high" on iOS, like this:

{   
  "to": "cHPpZ_s14EA:APA91bG56znW...",
  "priority": "high",
  "notification" : {
    "body" : "hello!",
    "title": "afruz",
    "sound": "default"
  }
}  

这篇关于iOS 未收到通过 API 发送的 Firebase 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆