本文介绍了如何使用Swift3检测与Firebase数据库的互联网连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 任何人都可以帮助我使用Swift 3检测与Firebase数据库的互联网连接?我使用这个函数从数据库下载数据。 $ b $ pre $ func loadData(){ Ref = FIRDatabase.database()。reference() Handle = Ref?.child(Posts)。queryOrdered(byChild:Des)。queryEqual(toValue:11) .observe(.childAdded,其中:{(snapshot)in if post = snapshot.value as?[String:AnyObject] { let img = Posts() img.setValuesForKeys(post) self.myarray.append(img) self.tableView.reloadData() } else { } }) } 解决方案如果您想要检测您的应用是否与Firebase数据库后端有连接,您可以侦听 /。方式/连接。来自关于检测连接状态的Firebase文档应该这样做: let connectedRef = FIRDatabase.database()。referenceWithPath(。info / connected) connectedRef.observeEventType(.Value,withBlock:{snapshot in if let connected = snapshot.value as?Bool where connected { print(Connected)} else { print(未连接)} }) Swift 3.1 let connectedRef = FIRDatabase.database()。reference(withPath:.info /连接) connectedRef.observe(.value,与:{快照在如果让connected = snapshot.value为?Bool,连接{ print(连接) } else { print(Not connected)} }) 目标C FIRDatabaseReference * connectedRef = [[FIRDatabase database] referenceWithPath : 方式/连接 @]; [connectedRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * snapshot){ if([snapshot.value boolValue]){ NSLog(@connected); } else { NSLog(@not connected); } }]; Can any one help me to detect internet connection with Firebase Database using Swift 3? I am using this function to download data from database. func loadData(){ Ref=FIRDatabase.database().reference() Handle = Ref?.child("Posts").queryOrdered(byChild: "Des").queryEqual(toValue: "11").observe(.childAdded ,with: { (snapshot) in if let post = snapshot.value as? [String : AnyObject] { let img = Posts() img.setValuesForKeys(post) self.myarray.append(img) self.tableView.reloadData() }else { } })} 解决方案 If you want to detect whether your app has a connection to the Firebase Database backend, you can listen for /.info/connected. This example from the Firebase documentation on detecting connection state should do the trick:let connectedRef = FIRDatabase.database().referenceWithPath(".info/connected")connectedRef.observeEventType(.Value, withBlock: { snapshot in if let connected = snapshot.value as? Bool where connected { print("Connected") } else { print("Not connected") }})Swift 3.1let connectedRef = FIRDatabase.database().reference(withPath: ".info/connected") connectedRef.observe(.value, with: { snapshot in if let connected = snapshot.value as? Bool, connected { print("Connected") } else { print("Not connected") }})Objective CFIRDatabaseReference *connectedRef = [[FIRDatabase database] referenceWithPath:@".info/connected"]; [connectedRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) { if([snapshot.value boolValue]) { NSLog(@"connected"); } else { NSLog(@"not connected"); }}]; 这篇关于如何使用Swift3检测与Firebase数据库的互联网连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 10:02