Swift Firebase电子邮件验证始终返回false

时间:2017-02-22 22:01:34

标签: ios swift firebase firebase-authentication

我一直在努力做到这一点,但isEmailVerified一直不假......甚至认为我已经清楚地验证了这封电子邮件。

  

用户创建

FIRAuth.auth()?.createUser(withEmail: Email.text!, password: Password.text!) { (user:FIRUser?, error:Error?) in
            if error == nil {

                let when = DispatchTime.now() + 1
                DispatchQueue.main.asyncAfter(deadline: when) {

                    FIRAuth.auth()?.currentUser?.sendEmailVerification(completion: { (error) in

                        let post2 = UIAlertController(title: "Verification sent", message: "A Email will be sent to activate your account.", preferredStyle: .alert)

                        post2.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in


                            self.performSegue(withIdentifier: "Sign_in", sender: nil)

                        }))

                        self.present(post2, animated: true, completion: nil)

                    })
                }

            } else {

                self.ErrorMsg.isHidden = false

                self.Password.text = ""

                print(error.debugDescription)
            }

        }
  

用户验证

FIRAuth.auth()?.addStateDidChangeListener { auth, user in

            if let user = user {
                Shared.shared.User_ID = user.uid
                Shared.shared.User_Email = user.email

                if user.isEmailVerified {

                    // Email Verified
                    self.performSegue(withIdentifier: "Launch_L", sender: nil)

                } else {

                    self.logOut.isHidden = false

                }

            } else {
                self.performSegue(withIdentifier: "Launch_S", sender: nil)
            }

        }

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:6)

我只需要刷新配置文件:

FIRAuth.auth()?.currentUser?.reload()

答案 1 :(得分:2)

迅速5:

(int) rint(yourVariable)