Firebase注销不在Swift中工作 [英] Firebase sign out not working in Swift
问题描述
我使用最新的Firebase API(3.2.1),并使用此代码检查用户是否已登录:
override func viewDidAppear(animated:Bool){
super.viewDidAppear(animated)
$ b $ if(self.navigationController!= nil){
self.navigationController!.setNavigationBarHidden true,animated:true)
$ b $ if(FIRAuth.auth()!= nil){
self.performSegueWithIdentifier(loginSuccessSegue,sender:self)
}
}
换句话说,如果auth对象存在,我切换到其他控制器。在该控制器上,我已经注销了正在签名的按钮,如下所示:
do {
try FIRAuth.auth ()?。signOut()
self.performSegueWithIdentifier(logoutSegue,sender:self)
} catch {
print(签出时出错!)
}
我不会在这个操作中遇到错误,但是当我切换到登录控制器时,这个验证对象是存在的然后我再次切换回控制器的数据。我也尝试在auth中检查当前的用户对象,它是存在的和有效的。
任何人都知道我是如何正确地签出?
试试看! FIRAuth.auth()!。signOut()
这是我在IBAction中的代码,它工作得很好:
尝试! FIRAuth.auth()!。signOut()
if let storyboard = self.storyboard {
let vc = storyboard.instantiateViewControllerWithIdentifier(firstNavigationController)as! UINavigationController
self.presentViewController(vc,animated:false,completion:nil)
}
I am using newest Firebase API (3.2.1) and I am using this code to check if user is signed in:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if(self.navigationController != nil){
self.navigationController!.setNavigationBarHidden(true, animated: true)
}
if(FIRAuth.auth() != nil){
self.performSegueWithIdentifier("loginSuccessSegue", sender: self)
}
}
In other words if auth object is present I am switching to other controller. On that controller I have sign out button which is doing sign out like this:
do{
try FIRAuth.auth()?.signOut()
self.performSegueWithIdentifier("logoutSegue", sender: self)
}catch{
print("Error while signing out!")
}
I do not get error on this operation but when I am switched to login controller, this auth object is present and I get switched back again to controller with data. I also tried checking the current user object in auth and it is present and valid.
Anyone knows how an I properly do sign out?
try using :
try! FIRAuth.auth()!.signOut()
This is the code I have in an IBAction, and it's working just fine :
try! FIRAuth.auth()!.signOut()
if let storyboard = self.storyboard {
let vc = storyboard.instantiateViewControllerWithIdentifier("firstNavigationController") as! UINavigationController
self.presentViewController(vc, animated: false, completion: nil)
}
这篇关于Firebase注销不在Swift中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!