当应用程序尝试连接到firebase-realtime-database时,我正在尝试检查错误。
我主要关心的是当用户第一次启动应用程序,但没有互联网连接时。我创建了对数据库的引用,并尝试观察单个事件,但是控制台日志开始抛出错误消息,并且我的代码没有捕获到任何错误消息。
//------- variable declaration
var ref:DatabaseReference?
//------- inside de method
ref = Database.database().reference(withPath: "myPath")
ref?.observeSingleEvent(of: .value, with: { (snapshot) in
//I cannot even fire up the observer, so I never get here
}){(error) in
//no error is captured here also
}
即使我注释或删除了observeSingleEvent,我也可以在控制台中看到抛出的错误,但我希望捕获它们。有人知道怎么做吗?
提前感谢
发布于 2019-06-19 08:05:58
在查询时离线不是“错误”。只要你的应用程序正在运行,并且你的代码在该位置附加了一个观察者,SDK就会继续尝试发出请求。
如果您想要detect the connection state,您可以在/.info/connected
附加一个观察者,以获取指示连接当前状态的回调。请注意,此信息可能已过期,因为停滞的连接直到一段时间后才会立即完全断开。
https://stackoverflow.com/questions/56658451
复制相似问题