Test Use Case:
In my scenario, I initialize my App in Xcode, login to firebase and run my app successfully. I then stop the debugger in Xcode, and then "turn Wifi off" on my MAC. I then initialize my App again in Xcode.
In the debugger, I see my code initialize an authentication listener and initialize based on the previously cached value of authenticated user information.
I also see the following exception in the console log.
2017-06-02 09:29:21.281 MusicPoll[7053] [Firebase/Core][I-NET901017] Encounter network error. Code, error: -1009, Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x60800005f7d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://play.googleapis.com/log, NSErrorFailingURLKey=https://play.googleapis.com/log, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=50, NSLocalizedDescription=The Internet connection appears to be offline.}
Since I am not connected to the network, I would like to detect this condition and ask the user to check his/her network connection and try again.
My question is which Firebase method should I used to check network connectivity and perhaps obtain an error. (I am unable to find an error code that might be returned in the listener's callback.)
My Code:
...
fileprivate var authListener : FIRAuthStateDidChangeListenerHandle!
FUIAuth.defaultAuthUI()?.providers = [FUIGoogleAuth()]
authListener = FIRAuth.auth()?.addStateDidChangeListener { [weak self] (auth: FIRAuth, user: FIRUser?) in
guard let strongSelf = self else { return }
if let activeUser = user {
strongSelf.hasUserBeenAuthenticated = true
strongSelf.user = activeUser
} else {
strongSelf.hasUserBeenAuthenticated = false
strongSelf.user = nil
}
print("\nFirebaseMgr[setupAuthorization]: hasUserBeenAuthenticated = \(strongSelf.hasUserBeenAuthenticated), user = \(String(describing: strongSelf.user))")
}