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

查看:57
本文介绍了适用于 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>"
}

我已经尝试删除priority"键,因为我看到有人说如果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 通知工作正常,有时当应用处于后台时.

推荐答案

移除 "notification" 键值对并添加 "content_available": true

Remove "notification" key value pair and add "content_available": true

看起来像这样

{ 
    "to" : "...",
    "priority": "high",
    "content_available": true,
    "data" : {
      ....
    }
}

这应该使它成为一个无声的 APNS,您需要使用相应的 APNS 委托方法进行处理.

This should make it a silent APNS and you need to handle with corresponding APNS delegate methods.

您需要通过委托来处理这个问题有关详细信息,请参阅此 Firebase 文档:https://firebase.google.com/docs/cloud-messaging/concept-options

You will need to handle this through delegates Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options

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

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