gpt4 book ai didi

ios - 注销时 Firebase 给出异常

转载 作者:可可西里 更新时间:2023-11-01 02:15:28 24 4
gpt4 key购买 nike

当我调用 try! 时,有人知道这是什么原因吗?

FIRAuth.auth()?.signOut()

这会发生 error here

回答当我们调用 signout 时,用户 uid 变为 nil,而观察者仍然需要 uid 来删除观察者。因此要修复它,我使用 addAuthStateDidChangeListener

FIRAuth.auth()?.addAuthStateDidChangeListener({ (auth: FIRAuth,user: FIRUser?) in
if user != nil {
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("ProfileViewController") as! ProfileViewController
controller.userID = (user?.uid)!
self.presentViewController(controller, animated: false, completion: nil)
}
else {
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("LoginRegisterViewController") as! LoginRegisterViewController
self.presentViewController(controller, animated: false, completion: nil)
}
})

最佳答案

问题当我进入这个 View 时,我将调用我传递给 (user?.uid)! 的观察者函数。但是,当我们注销时,(user?.uid)!当观察者仍然需要调用 (user?.uid) 时将为 nil!

解决方案因此,为了解决这个问题,我在该类中创建了一个名为 userID 的变量并传递 (user?.uid)!当我移动到那个 View 时到 userID

这是移动到那个 View 的代码

FIRAuth.auth()?.addAuthStateDidChangeListener({ (auth: FIRAuth,user: FIRUser?) in
if user != nil {
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("ProfileViewController") as! ProfileViewController
controller.userID = (user?.uid)!
self.presentViewController(controller, animated: false, completion: nil)
}
else {
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("LoginRegisterViewController") as! LoginRegisterViewController
self.presentViewController(controller, animated: false, completion: nil)
}
})

关于ios - 注销时 Firebase 给出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39043702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com