应用长时间在后台运行时,Firestore监听器被杀死 [英] Firestore listener killed when app goes in background for a long time

查看:61
本文介绍了应用长时间在后台运行时,Firestore监听器被杀死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,无论何时用户登录,我都会监听Firestore查询.应用程序在后台运行一段时间后,监听器将被取消,并且客户端不会收到有关任何新更改的通知.

In my app I'm listening for a Firestore query whenever the user signs in. After the app goes in background for some time, the listener gets cancelled and the client doesn't get notified of any new changes.

我怎么知道SDK是否取消了监听器?处理此问题的正确方法是什么?

How do I know if a listener has been cancelled by the SDK? What's the proper way of handling this?

推荐答案

在大多数操作系统上,此操作由系统本身自动完成,以节省电池寿命.是否可以检测到这种情况,以及如何检测,取决于操作系统.

On most operating system this is done automatically by the system itself, in order to preserve battery life. Whether it is possible to detect this situation, and how, depends on the OS.

在大多数情况下,最好依靠另一种机制将更新交付给未被积极使用的应用程序,例如Firebase Cloud Messaging-您可以从例如Cloud Functions调用它,以将消息交付给后台应用程序.有关此示例,请参阅在发生有趣的事情时通知用户的Firebase文档.

In most cases it is better to depend on another mechanism to deliver updates to an app that is not actively being used, such as Firebase Cloud Messaging - which you can call from for example Cloud Functions to deliver messages to backgrounded apps. For an example of this, see the Firebase documentation on notifying users when something interesting happens.

这篇关于应用长时间在后台运行时,Firestore监听器被杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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