【问题标题】:Why isn't my sendEmailVerification(beforeUpdatingEmail) function always returning an error?为什么我的 sendEmailVerification(beforeUpdatingEmail) 函数不总是返回错误?
【发布时间】:2020-10-08 00:22:53
【问题描述】:

我正在尝试在更新用户的电子邮件地址之前发送一封电子邮件验证电子邮件。但是,目前这行不通。我不确定为什么。我尝试了各种不同的方法。我认为这可能是由于我在user?.sendEmailVerification(beforeUpdatingEmail: ) 之后放置的字符串,但我不确定。任何帮助将非常感激。我已经被困了一段时间了。

@IBAction func setEmailIsTapped(_ sender: Any) {
            let error = validateEmailField()
            if error != nil {
                print(error!) //Needs a Label
            }
            let db = Firestore.firestore()
                let userID = Auth.auth().currentUser?.uid
             let emailSearch = db.collection("users")
                let email = emailTextField.text!
            let query = emailSearch.whereField("email", isEqualTo: email).getDocuments { (snapshot, error) in
                 if let error = error {
                    print("An error was encountered")
                 } else {
                     if snapshot!.isEmpty {
                        let user = Auth.auth().currentUser
                        user?.sendEmailVerification(beforeUpdatingEmail: self.emailTextField.placeholder!, completion: { (error) in
                            if error != nil {
                                print("Error sending update email")
                            } else {
                                print("Success")
                            }
                        })
                    }
                }

        }
        }

【问题讨论】:

标签: ios swift xcode firebase google-cloud-firestore


【解决方案1】:

您应该传入email 而不是UITextFieldplaceholder 作为参数,如下所示:

user?.sendEmailVerification(beforeUpdatingEmail: email, completion: { (error) in
    if error != nil {
        print("Error sending update email")
    } else {
        print("Success")
    }
})

【讨论】:

  • 您好,感谢您的回复。我试过这样做,它仍然返回错误而不是成功。你还有什么想法吗?
猜你喜欢
  • 2017-09-24
  • 2013-01-09
  • 1970-01-01
  • 2021-11-16
  • 1970-01-01
  • 2022-01-16
  • 2011-11-25
  • 2020-02-22
  • 1970-01-01
相关资源
最近更新 更多