所以在我的应用程序中,我只是让用户可以选择删除他们的帐户,而且效果很好。但是,删除帐户后,应用程序崩溃了。我认为这是因为它正在尝试搜索用户但不存在。
这是我的代码:
let loginController = LoginController()
func deleteAccount() {
let user = Auth.auth().currentUser
let userId = Auth.auth().currentUser?.uid
let databaseUser = Database.database().reference().child("users").child(userId!)
user?.delete { error in
if let error = error {
print(error)
} else {
self.present(self.loginController, animated: true, completion: nil)
}
}
databaseUser.removeValue(completionBlock: { (error, ref) in
if error != nil {
print(error)
} else {
self.present(self.loginController, animated: true, completion: nil)
} //Without doing this the user's account only gets deleted in the Authentication, not the whole database. I think this is the problem here?
})
}
提前致谢!
最佳答案
首先,您需要删除用户数据库,为此您需要 let userId = Auth.auth().currentUser?.uid
,只有当用户本身在您的后端,然后你继续删除auth
。
func deleteAccount() {
let user = Auth.auth().currentUser
let userId = Auth.auth().currentUser!.uid
let databaseUser = Database.database().reference().child("users").child(userId)
databaseUser.removeValue(completionBlock: { (error, ref) in
if error != nil {
print(error)
} else {
user?.delete { error in
if let error = error {
print(error)
} else {
self.present(self.loginController, animated: true, completion: nil)
}
}
})
}
如果这仍然不起作用,请使用调试工具跟踪用户的生命周期....
关于ios - 删除用户后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45598552/