未收到密码重置邮件Firebase

时间:2018-10-18 13:52:28

标签: swift firebase firebase-authentication

图片试图在我的应用中实现“忘记密码”功能。但是未发送重置邮件。代码是否错误?还是我必须在Firebase中设置一些东西才能使其正常工作?

  @IBAction func forgotPasswordButton(_ sender: UIButton) {
        let forgotPasswordAlert = UIAlertController(title: "Forgot password?", message: "Please enter registerd email address", preferredStyle: .alert)
        forgotPasswordAlert.addTextField { (textField) in
            textField.placeholder = "Email address"
        }
        forgotPasswordAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        forgotPasswordAlert.addAction(UIAlertAction(title: "Reset Password", style: .default, handler: { (action) in
            let email = forgotPasswordAlert.textFields?.first?.text
            Auth.auth().sendPasswordReset(withEmail: email!, completion: { (error) in
                DispatchQueue.main.async {

                    if let error = error {
                        let resetFailedAlert = UIAlertController(title: "Reset Failed", message: error.localizedDescription, preferredStyle: .alert)
                        resetFailedAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                        self.present(resetFailedAlert, animated: true, completion: nil)
                    } else {
                        let resetEmailSentAlert = UIAlertController(title: "Reset email sent successfully", message: "Check your email", preferredStyle: .alert)
                        resetEmailSentAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                        self.present(resetEmailSentAlert, animated: true, completion: nil)
                    }
                }
            })
        }))

        self.present(forgotPasswordAlert, animated: true, completion: nil)
    }

0 个答案:

没有答案