【发布时间】:2016-05-31 02:45:33
【问题描述】:
我在使用 Swift 应用检测 Firebase 连接状态时遇到问题。一旦我的视图控制器启动,它就会立即显示,并且 alertView 显示我的连接状态已关闭。无论应用程序启动时的实际状态如何,它每次都会这样做。一旦应用程序启动,就会可靠地报告连接状态。即使我切换到另一个视图控制器并返回到原来的视图控制器,它也不会再次报告连接断开。它仅在应用程序首次启动时发生。这是我在 viewDidLoad 方法中实现连接状态检测的代码。有人有什么建议吗?
override func viewDidLoad() {
//Do these things once when the app first starts up
super.viewDidLoad()
mapView.delegate = self
setMapInitialState()
let connectedRef = FIRDatabase.database().referenceWithPath(".info/connected")
connectedRef.observeEventType(.Value, withBlock: {snapshot in
let connected = snapshot.value as? Bool
if connected != nil && connected! {
self.showAlertView("Alert", message: "Connection to server restored - all pending catches will be updated")
self.refreshCatches()
} else {
self.showAlertView("Alert", message: "Connection to server lost - catches by others may not be up to date")
}
})
}
【问题讨论】:
标签: swift firebase firebase-realtime-database