Firebase数据库观察员的持久性如何? [英] Just how persistent are Firebase database observers?

查看:110
本文介绍了Firebase数据库观察员的持久性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定在XCode iOS模拟器上运行测试,以查看Firebase数据库中某个位置的观察者是否会继续触发,即使该应用程序在后台也是如此.事实证明确实如此,但是我想知道在应用终止之前是否不确定,或者一段时间后它实际上是否会停止.已经很长时间了,每当我手动更新观察者正在查看的数据库中的值时,观察者仍然会触发.另请注意,我的应用程序功能中未启用任何背景模式,因此,尽管没有任何明确的背景模式,观察者似乎仍可以保持背景模式.

I decided to run a test on the XCode iOS simulator to see if an observer to a location in the Firebase database would continue to fire even when the app is in the background. Turns out it does, but I am wondering if this is indefinite until the app terminates or if it will actually stop after some time. It's been a very long time and the observers still fires whenever I manually update the value in the database that the observer is looking at. Also note that I don't have any background modes enabled in my app's capabilities, so it seems that the observer can persist in background mode despite no explicit background modes of any kind.

一方面,我很高兴观察者留在背景中,因为这对我有帮助,但我有点急于知道为什么允许这种情况发生,因为默认情况下,iPhone通常相当保守在后台做事.

On the one hand I am very glad that the observer stays on in background as this is helpful to me, but I am a bit anxious to know why this is allowed to happen as iPhone is generally quite conservative by default when it comes to doing stuff in the background.

推荐答案

虽然在单个测试案例中侦听器可能保持活动状态,但您不应依赖Firebase数据库侦听器来进行后台数据传递.

While the listener may stay active in your single test case, you should not rely on Firebase Database listeners for background data delivery.

只要连接保持打开状态,侦听器就会保持活动状态.由操作系统决定何时关闭连接.在这种情况下,iOS模拟器很有可能具有与物理设备不同的行为.

The listener stays active as long as the connection stays open. It is up to the operating system to determine when it closes the connection. There is a good chance that the iOS emulator has different behavior in this case than a physical device would have.

这篇关于Firebase数据库观察员的持久性如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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