我目前正在开发一个应用程序,它有一个带有登录按钮和主菜单按钮的登录页面。我已经创建了一切,并且目前工作得很好。我使用 Firebase 作为我的后端数据库。
我想创建一个“忘记密码”按钮,我已经这样做了,看起来它可以工作,但唯一的问题是它在发送电子邮件时不会给我一个警报,它只是发送它,但我得到了当我输入不在用户身份验证中的电子邮件时发出警报。下面是我的忘记密码按钮的代码:
@IBAction func frgtpassTapped(_ sender: Any) {
Auth.auth().sendPasswordReset(withEmail: emailTextField.text!) { error in
if self.emailTextField.text?.isEmpty==true{
let resetFailedAlert = UIAlertController(title: "Reset Failed", message: "Error: \(String(describing: error?.localizedDescription))", preferredStyle: .alert)
resetFailedAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(resetFailedAlert, animated: true, completion: nil)
}
if error != nil && self.emailTextField.text?.isEmpty==false{
let resetEmailAlertSent = UIAlertController(title: "Reset Email Sent", message: "Reset email has been sent to your login email, please follow the instructions in the mail to reset your password", preferredStyle: .alert)
resetEmailAlertSent.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(resetEmailAlertSent, animated: true, completion: nil)
}
}
}
如果有人对这篇文章投反对票,我接受,但如果您这样做,请在下面评论原因。任何帮助将非常感激!
最佳答案
Please this code
Auth.auth().sendPasswordReset(withEmail: emailTextField.text!) { error in
DispatchQueue.main.async {
if self.emailTextField.text?.isEmpty==true || error != nil {
let resetFailedAlert = UIAlertController(title: "Reset Failed", message: "Error: \(String(describing: error?.localizedDescription))", preferredStyle: .alert)
resetFailedAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(resetFailedAlert, animated: true, completion: nil)
}
if error == nil && self.emailTextField.text?.isEmpty==false{
let resetEmailAlertSent = UIAlertController(title: "Reset Email Sent", message: "Reset email has been sent to your login email, please follow the instructions in the mail to reset your password", preferredStyle: .alert)
resetEmailAlertSent.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(resetEmailAlertSent, animated: true, completion: nil)
}
}
}
关于ios - Firebase 重置密码 IOS 应用 xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51423286/