ios - Firebase 重置密码 IOS 应用 xcode

标签 ios swift firebase firebase-authentication

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

相关文章:

iphone - 核心位置 : How do I wake my app up when iPhone turned on after significant location change?

ios - 使用 Swift 在 TableView 中显示 JSON 数据

ios - 在 Swift 项目中为生产禁用 NSLog

ios - 如何为目标 V​​C 的子项设置协议(protocol)委托(delegate)?

iphone 开发 : reaching objects from different viewControllers

ios - 找到信标,但 RSSI 为 0,准确度 -1 且接近度未知

ios - Cordova iOS 插件在构建后失败,除非我先删除平台和插件 JSON

android - 从 firebase android 获取数据时项目终止

angular - 需要取消订阅 Firestore/Angularfire2 订阅

Firebase Documentsnapshot 映射到 Flutter 中的 Json 对象