我已开始从 Firebase 实时数据库迁移到 Cloud Firestore。我需要一种方法,让应用程序在 Firestore 的连接状态发生变化时(从在线到离线,反之亦然)收到警报。为了清楚起见,我不需要将其写入数据库以供应用程序的其他实例查看。这纯粹是为了向用户提供连接已断开的指示。在实时数据库中,我可以通过将值监听器附加到“.info/connected”引用来实现此目的。但我似乎无法在 Firestore 中执行此操作。
或者,如果我可以在 Firestore 模块中监听“待处理更新”值,该值会响应存在脱机待处理数据库同步的数据,该值也可以工作。
最佳答案
Cloud Firestore 中没有与 Firebase 实时数据库的 .info/connected
等效的版本。事实上,它是 blog post comparing Realtime Database and Firestore 中明确调用的用例之一。 :
The Realtime Database has native support for presence -- that is, being able to tell when a user has come online or gone offline. While we do have a solution for Cloud Firestore, it's not quite as elegant.
Firestore 文档描述了可能的 implementation of a presence system by combining Realtime Database and Firestore .
关于firebase - Cloud Firestore 相当于实时数据库 ".info/connected"引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46802136/