首页 > 解决方案 > Firebase 重置密码 IOS App xcode

问题描述

我目前正在开发一个具有登录页面的应用程序,该页面带有登录按钮和主菜单按钮。我已经创建了所有内容,并且目前工作得很好。我使用 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)
        }
    }
}

如果有人反对这篇文章,我接受,但如果你反对,请在原因下方评论。任何帮助将非常感激!

标签: iosswiftfirebasefirebase-authentication

解决方案


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)
                }
            }
        }

推荐阅读