Reputation: 4519
I want to check if an device (in this case an IOS device) has access to the Firebase Realtime Database.
So I have created this method:
private func isConnected(completionHandler : @escaping (Bool) -> ()) {
let connectedRef = Database.database().reference(withPath: ".info/connected")
connectedRef.observe(.value, with: { snapshot in
completionHandler((snapshot.value as? Bool)!)
})
}
This method is working perfect. And I'm using it like this in every method where I'm doing something with the realtime database:
isConnected { (connected) in
if(connected){
//do your things
} else {
print("network error")
}
}
But now my question, what if you get the network error. How do you know if your device has no internet connection or the Firebase service is down? What is a good approach to do this? Because the only thing I know right now is that I can't reach the realtime database.
So my question is, how can I get more detailed information? Isthe device offline? Is firebase down? etc etc.
Upvotes: 1
Views: 3019
Reputation: 598728
Firebase's .info/connected
only signals whether your app is connected to its Firebase Database backend. It does not detect general network connectivity.
To determine the latter, try one of the many answers from [this list]. Including How to check for an active Internet connection on iOS or OSX?, Easiest way to detect Internet connection on iOS?, and Check for internet connection with Swift.
Upvotes: 1