大家好,我的 iOS 应用程序出现了一个非常奇怪的问题。例如,我现在在“Test1”用户个人资料页面上,单击注销按钮后,我的应用程序将通过 firebase 成功注销,但如果我使用名为“Test2”的新帐户再次登录,登录个人资料页面后仍然会成为“测试 1”的个人资料页面。但是,如果现在我终止该应用程序并重新打开它,个人资料页面将获取所有“Test2”个人资料信息。谁能告诉我可能是什么问题?非常感谢。这是我的注销代码和登录代码。
func handleLogOut(){
do{
try Auth.auth().signOut();
} catch let logoutError {
print(logoutError)
}
}
func login(){
guard let email = emailTextField.text, let password = passTextField.text else{
return
}
Auth.auth().signIn(withEmail: email, password: password, completion: {(user, error) in
if error != nil {
print(error)
error
}
})
}
最佳答案
当应用程序激活时,请保持检查。
if Auth.auth().currentUser != nil {
// User is signed in.
// ...
} else {
// No user is signed in.
// ...
}
我相信您会看到用户已注销。因此,请根据您的应用要求导航到登录页面或屏幕。如下修改您的代码,使注销时 currentUser = nil 并在登录时赋值。
func handleLogOut(){
do{
try Auth.auth().signOut();
currentUser = nil
} catch let logoutError {
print(logoutError)
}
}
func login(){
guard let email = emailTextField.text, let password = passTextField.text else{
return
}
Auth.auth().signIn(withEmail: email, password: password, completion: {(user, error) in
if error != nil {
print(error)
error
} else {
currentUser = user
}
})
}
关于ios - Swift Firebase 注销问题,只有在重新打开应用程序后才能成功注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47548328/