gpt4 book ai didi

swift - Firebase 用户无法注销 - Swift

转载 作者:行者123 更新时间:2023-11-28 12:42:10 26 4
gpt4 key购买 nike

  1. 我在 Xcode 模拟器中运行该应用程序并使用用户名和密码登录,然后我注销,logOutOutletbookingsOutlet 被隐藏,logInOutlet 按钮显示。到目前为止,它的行为符合预期。

    • 2

接下来,从 Xcode 停止应用程序并再次运行它,但现在它的行为就像我已经登录一样:显示 logOutOutlet,bookingsOutlet,隐藏 logInOutlet。当应用程序暂停、终止或删除时,它的行为相同。 (即,在 Xcode 或 cmd + H * 2 中停止并向上滑动。)现在,假设我在下一个 ViewController 中有一个事件的登录 session ,我尝试从 FireBase 实时数据库检索数据,但我收到此错误。 错误域=com.firebase 代码=1“权限被拒绝”用户信息={NSLocalizedDescription=权限被拒绝}。为什么我不能完全注销?

@IBAction func logOut(sender: AnyObject) {
// if the current user is logged in, try to log out and if logout is successful:
// hide: logOut button & bookings button
// show: logIn button
if FIRAuth.auth() != nil {

do {
try FIRAuth.auth()?.signOut()

print("the user is logged out")
} catch let error as NSError {
print(error.localizedDescription)
print("the current user id is \(FIRAuth.auth()?.currentUser?.uid)")
}

self.logInOutlet.hidden = false
self.logOutOutlet.hidden = true
self.bookingsOutlet.hidden = true
} // end of if.. FIRAuth.auth()
}

override func viewDidLoad() {
super.viewDidLoad()

// if the user is logged out
// hide: logOut button & bookings button
// show: logIn button
// if FIRAuth.auth()?.currentUser?.uid == nil {
if FIRAuth.auth() == nil {

self.logInOutlet.hidden = false
self.logOutOutlet.hidden = true
self.bookingsOutlet.hidden = true

// it still prints the user id, why?
if let userNOTLogged = FIRAuth.auth()?.currentUser?.uid {
print("User should NOT be logged \(userNOTLogged)")

}



// if the user is logged in
// hide: logIn Button
// show: logOut button & bookings button
} else if

FIRAuth.auth() != nil {
self.logInOutlet.hidden = true
self.logOutOutlet.hidden = false
self.bookingsOutlet.hidden = false
}
}



// Log in code


FIRAuth.auth()?.signInWithEmail(email.text!, password: password.text!, completion: { (authData, error) in

let customError = error?.localizedDescription
if error != nil {
print(customError)

// display an alert with the error
self.displayAlert()

} else {
print("The user has been logged in")


//if signIn was successful, instantiate the view controller with identifier SWrevelViewidentifier
let toMenuOptions = self.storyboard?.instantiateViewControllerWithIdentifier("SWrevelViewidentifier")
self.presentViewController(toMenuOptions!, animated: true, completion: nil)

}
})
}

最佳答案

我遇到了完全相同的问题。由于这种情况会在您重新启动时发生,请尝试将此代码放入您的 app.delegate 中。

FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in
if let user = user {
// User is signed in.
} else {
// No user is signed in.
}
}

关于swift - Firebase 用户无法注销 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39175359/

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