【发布时间】:2019-04-05 02:24:33
【问题描述】:
快速问题我试图让用户选择在 Xcode 上使用 swift 从 firebase 中删除他们的帐户。
我目前有一个“删除”按钮,它会导致一个 UIAlert 询问用户是否确定他们想要像这样删除他们的帐户(以防万一)
我的代码如下
//Handles delete current user account (not fnished yet)
@IBAction func deleteAccount(_ sender: Any) {
createAlert2(title: "Delete Account", message: "Are you sure you want to delete your account? This will permanently erase your account.")
}
到这个函数
func createAlert2 (title:String, message:String){
let alert2 = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert2.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
alert2.dismiss(animated: true, completion: nil)
}))
alert2.addAction(UIAlertAction(title: "Delete", style: UIAlertActionStyle.destructive, handler: { (action) in
let user = Auth.auth().currentUser
user?.delete { error in
if error != nil {
// An error happened.
} else {
// Account deleted.
print("user deleted")
}
}
let controller2 = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MenuViewController") as! MenuViewController
self.present(controller2, animated: true, completion: nil)
}))
self.present(alert2, animated: true, completion: nil)
我的目标是删除用户并将他们发送回那个 MenuViewController。但它似乎所做的只是将用户发送到该菜单视图,而不是实际删除他们在 firebase 上的帐户。任何帮助表示赞赏,我总是喜欢并勾选答案。谢谢:)
【问题讨论】:
-
我建议在 if err 检查中添加 print("an error occurred (errText)" 。事实上,如果有错误你不会知道。
-
我真的不知道它是如何工作的。但现在它实际上只是通过将其放入删除用户。打印(“错误删除用户”)。谢谢好心的先生。
标签: swift xcode firebase authentication firebase-authentication