我是 Firebase 的新手。我正在尝试检查用户是否已登录,并通过引用 Firebase 文档,推荐的方法是添加 FIRAuthStateDidChangeListenerHandle
。
我的代码如下:
handle = FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
//here, we add code to see if we are supposed to be loggin or not
print("hello world")
if user != nil{
self.isLogin = true
}else{
self.isLogin = false
}
})
但是,在我检查之后,似乎 FirAuth.auth()
是一个 nil 并且根本没有调用整个 block 。
谁知道这里出了什么问题?
最佳答案
这看起来像是未正确设置的 Firebase
。您是否遵循了所有步骤 here ?具体来说,您是否在您的 AppDelegate
中调用了 FIRApp.configure()
?如果没有此配置调用,您的 FIRAuth
可能会是 nil
。
关于ios - Firebase addStateDidChangeListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41234433/