大家好,我的ios应用程序有一个非常奇怪的问题。例如,我现在在“Test1”用户配置文件页上,单击“注销”按钮后,我的应用程序将通过firebase成功注销,但如果我使用名为“Test2”的新帐户再次登录,登录配置文件页后仍然是“Test1”的配置文件页。但是,如果现在我终止应用程序并重新打开它,profile页面将获取所有“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
}
})
}