等同于实时数据库".info/connected"的Cloud Firestore参考? [英] Cloud Firestore Equivalent to Realtime Database ".info/connected" ref?

查看:46
本文介绍了等同于实时数据库".info/connected"的Cloud Firestore参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始从Firebase实时数据库迁移到Cloud Firestore.我需要一种方法来在Firestore的连接状态更改时(从联机到脱机,反之亦然)提醒应用程序.为了清楚起见,我不需要将此信息写入数据库,以供其他App实例查看.这纯粹是为了向用户提供其连接已断开的指示符.在实时数据库中,我可以通过将值侦听器附加到".info/connected"引用来实现此目的.但似乎我无法在Firestore中做到这一点.

I have started migrating over from Firebase Realtime Database to Cloud Firestore. I need a way for the app to be alerted to when Firestore's connection state changes, online to offline and vice versa. For clarity, I do not need this written into the Database for other instances of the App to see. This is purely for providing an Indicator to the User that their connection has dropped. In Realtime database I could achieve this by attaching a value listener to the ".info/connected" reference. But It doesn't seem that I can do this in Firestore.

或者,如果我可以在Firestore模块中侦听"Pending Updates"值,则表示存在脱机暂挂数据库同步处理的数据也将起作用.

Alternatively, if there is "Pending Updates" value I could listen to in the Firestore Module, that responds to there being data held Offline pending Database sync that would also work.

推荐答案

Cloud Firestore中没有等效于Firebase Realtime Database的.info/connected.实际上,这是

There is no equivalent to Firebase Realtime Database's .info/connected in Cloud Firestore. It's in fact one of the use-cases that is explicitly called on in the blog post comparing Realtime Database and Firestore:

实时数据库具有对状态的本机支持,即能够判断用户何时联机或脱机.尽管我们确实有Cloud 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文档描述了可能的通过结合使用实时数据库和Firestore实现在线状态系统.

The Firestore documentation describes a possible implementation of a presence system by combining Realtime Database and Firestore.

这篇关于等同于实时数据库".info/connected"的Cloud Firestore参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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