1

当我打电话试试时,有没有人知道这个原因?Firebase在注销时会出现异常

FIRAuth.auth()?.signOut()

这种情况 error here

ANSWER 当我们调用signout,用户UID变为零,而观察者仍然需要为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) 
       } 
      }) 
+1

是'User'零代码?将'print(user == nil)'放在代码中断的行之前。查看是否将“true”打印到控制台。 –

+0

我确保用户不是n,而且我已经尝试使用observeSingleEventOfType 所以一旦我登录,我将从数据库中提取我的用户信息,信息已显示在我的用户界面上。所以之后当我想注销时,会发生运行时错误。 –

+0

很棒,你找到了解决你自己的问题。你能把它作为答案发布吗?自我回答在StackOverflow中完全可以接受,并且如果它们是真正的答案,则可以更清楚地进行跟踪。 –

回答

1

问题 当我去这个观点,我会打电话给观察者功能,这是我传递(用户?.uid)!但是当我们注销时,(user?.uid)!当观察者仍然需要调用(user?.uid)时,它将为零!

解决方案 因此,要解决这个问题,我创建了一个叫做用户ID在类变量和传递(用户?.uid)!以用户ID当我移动到该视图

这里是移动到该视图

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) 
      } 
     })