在viewDidDisappear中删除Firebase身份validation

我正在使用Firebase的新框架,并试图在“login”和“注册”VC中分别监视用户的login状态。 问题是,如果login状态在注册视图上更改,那么“login”视图上的“身份validation状态”也会被调用。 我的问题是,如何删除身份validation状态? 我在Firebase网站上find了这个语法,但是在考虑我的代码的auth状态的时候有些困惑:

FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in if let theUser = user { // User is signed in. print("LOGGED IN!!!! :::: \(theUser)") self.dismissViewControllerAnimated(true, completion: nil) } else { // No user is signed in. print("Need to login first.") } } 

用于删除身份validation的代码,但不确定要传入的内容。

 FIRAuth.auth()?.removeAuthStateDidChangeListener(FIRAuthStateDidChangeListenerHandle) 

我说我传入一个FIRAuthStateDidChangeListenerHandle ,但我怎么获得这个,或者我重写我的authState代码不同?

只需将auth存储在一个variables中

 self.authListener = FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in if let theUser = user { // User is signed in. print("LOGGED IN!!!! :::: \(theUser)") self.dismissViewControllerAnimated(true, completion: nil) } else { // No user is signed in. print("Need to login first.") } } 

并稍后删除它

 FIRAuth.auth()?.removeAuthStateDidChangeListener(self.authListener)