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.