适用于iOS的Firebase FCM静音推送通知 [英] Firebase FCM silent push notifications for iOS

查看:1105
本文介绍了适用于iOS的Firebase FCM静音推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS上遇到静音通知问题。

I have a problem with silent notifications on iOS.

当我的应用程序处于后台时,我没有收到FCM发送的无提示通知。但如果我尝试直接发送到APNS,则会成功收到通知。

When my application is in background, I don't receive silent notification sent by FCM. But if I try to send directly to APNS, the notification is successfully received.

这是发送给FCM的JSON:

This is the JSON sent to FCM:

{ 
"to" : "<token>",
"priority": "high",
"content_available": true,
"data" : {
  "<key>" : "<string>",
  "<key2>" : "<string>"
}

}

这是直接发送给APNS的JSON:

This is the JSON sent directly to APNS:

{
  "aps": {
    "content-available": 1
  },
  "<key>": "<string>",
  "<key>": "<string>"
}

我已经尝试删除优先键,因为我看到有人说如果已经设置了content_available,我不应该设置优先级。它不起作用。

I have already tried to remove the "priority" key because I saw someone saying that I shouldn't set the priority if the "content_available" is already set. It didn't work.


  1. 我在XCode>功能中启用了推送通知。

  2. 我在XCode>功能的后台模式中选中了远程通知。

  3. 当应用程序处于前台时,有时当应用程序处于后台时,FCM通知正常工作。


推荐答案

我找到了解决方法。我在通知字段中为声音设置了一个空值,即使应用程序处于后台,也会传送无提示通知。

I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.

{ 
    "to" : "...",
    "priority": "high",
    "notification": {
        "sound": ""
    },
    "data" : {
      ....
    }
}

我的预感是Apple不允许以高优先级和某种方式通知的静默通知:{声音:}欺骗APNS,这个通知不是沉默一个。

My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.

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

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