ios - Firebase addStateDidChangeListener

标签 ios swift firebase firebase-authentication

我是 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/

相关文章:

java - 将 dialogflow 依赖项添加到我的 android 应用程序后出现重复类错误

android - 如何在 Firestore 中检索子集合的文档?

iphone - 在 iPhone 上从数据库中获取用户图片

ios - 在 UITableView 中为原型(prototype)单元格添加边距

ios - 从 NSArray 中获取具有 CoreData 内容的字段

xcode - <未知> :0: error: unexpected input file:

uitextfield - UIAlertController 的文本字段委托(delegate)未被调用

android - 如何在 FirebaseInstanceIdService 之外访问 Firebase token ?

ios - XCode 颜色差异

ios - 通过 Storyboard使用自动布局创建拉伸(stretch)标题