Firebase 数据库观察者有多持久? [英] Just how persistent are Firebase database observers?

查看:28
本文介绍了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天全站免登陆