Firebase静默通知丢失(iOS) [英] Firebase silent notification lose (iOS)

查看:94
本文介绍了Firebase静默通知丢失(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FCM通过静默通知进行主题消息传递.

I used FCM for topic messaging with silent notification.

我有android和iOS应用.

I have android and iOS app.

这是我在PHP中使用的示例JSON

This is the sample JSON that I used in PHP

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

我用android和iOS为同一主题下标,然后发送给这两个主题.

I subscripted the same topic with android and iOS, then send to both.

iOS部分总是丢失一些消息

iOS part always lost some messages

EX:

发送10条消息

android:10

android: 10

iOS:8

我在网上搜索,仅发现电池电量不足20%时,它将丢失消息.

I searched the web and only found if battery level is less than 20% it will lost message.

(我测试了这种情况是否确实发生过,但与我的情况无关.在我的测试情况下,电池电量始终很高)

(I test this behavior it's really happened, but not related to my cases. My battery level is always high in my test cases)

我有一些问题,有人可以帮助我吗?

I have some questions, can someone help me?

  1. 还有其他可能导致丢失消息的情况吗?

  1. Is any other possible situation to cause lose message?

我是否丢失了任何需要验证的代码?(例如:iOS部分)

Is any code I lost and need to check? (EX: iOS part)

或者丢失某些消息是正常现象,FCM不保证发送100%

Or lost some message is normal, FCM doesn't guarantee to send 100%

推荐答案

Firebase不保证使用可用的内容在iOS中传递静默通知.

Firebase does not guarantee delivery of silent notifications in iOS by using content-available.

按照firebase 文档用于提供内容,

As per firebase documentation for content-available,

"请注意,不能保证APN中的无提示通知会被传递,并且取决于用户打开低功耗模式",强制退出应用程序等因素.在Android上,默认情况下,数据消息会唤醒应用程序."

"Note that silent notifications in APNs are not guaranteed to be delivered, and can depend on factors such as the user turning on Low Power Mode, force quitting the app, etc. On Android, data messages wake the app by default."

这是我认为可能对您有用的解决方法.

Here's a workaround that I think might work for you.

对于您的iOS设备,发送一个带有mutable_content为true的通知有效负载,一个虚拟通知对象以及您数据对象中的某种标志,表明这是一个静默通知(类似于isSilentNotif = true).

For your iOS device, send a notification payload with mutable_content as true, a dummy notification object and some sort of flag in your data object that indicates this is meant to be a silent notification(something like isSilentNotif=true).

现在,编写一个扩展UNNotificationServiceExtension的Notificationservice.在通知显示给用户之前,您将在通知服务中获得控制权.在这里检查包含的标记(isSilentNotif),如果标记为true,则以编程方式隐藏通知,并在此处执行您要执行的后台操作.

Now write a notificationservice that extends UNNotificationServiceExtension. You will get control in your notification service before the notification is displayed to the user. Here check for the flag you included (isSilentNotif) and hide the notification programmatically if the flag is true and perform the background operation you wanted to perform here.

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

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