离线时不返回Firebase数据库查询 [英] Firebase database query not returning when offline

查看:57
本文介绍了离线时不返回Firebase数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Firebase数据库上运行查询,如果用户处于脱机状态,我想向用户显示一个弹出窗口,提示他们再次尝试.但是,脱机时查询不会返回.

I am trying to run a query on the firebase database and if the user is offline I want to display a pop up to the user prompting them to try again. However the query does not return when offline.

databaseRef.queryEqual(toValue: "someValue").observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in
    print(snapshot) //this is never called when user is offline
}) { (error) in
    print(error)    //neither is this
}

运行此查询并检测用户是否离线的最佳策略是什么?

What is the best strategy to run this query and detect if the user was offline?

推荐答案

由于数据库客户端未连接到其后端,并且不了解其缓存中的位置,因此它无法调用您的回调.

Since the database client is not connected to its backend and it doesn't have any knowledge of the location in its cache, it cannot invoke your callback.

您可以通过观察.info/connected来检测Firebase客户端是否已连接到其后端.有关检测连接状态的示例,请参见 Firebase文档.

You can detect whether the Firebase client is connected to its backend by observing .info/connected. See the Firebase documentation for an example of detecting connection state.

这篇关于离线时不返回Firebase数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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