Firebase电子邮件验证无法验证帐户

时间:2016-10-14 05:54:36

标签: ios swift firebase firebase-authentication

我检查了用户是否通过电子邮件进行了验证。但是,无论我发送和确认了多少封电子邮件,验证状态仍为A = vertcat('E1', A) A = 'E1' [ 1] [ 2] 'ABC' @(n)sin(n) 。我在检查时做错了吗?

false

2 个答案:

答案 0 :(得分:9)

我如何实现此功能是添加 NSTimer ,其时间间隔将检查用户是否已经过验证,然后在验证完成后终止计时器。

var verificationTimer : Timer = Timer()    // Timer's  Global declaration

self.verificationTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(LoginViewController.checkIfTheEmailIsVerified) , userInfo: nil, repeats: true)

检查当前用户状态的功能: -

func checkIfTheEmailIsVerified(){

    FIRAuth.auth()?.currentUser?.reload(completion: { (err) in
        if err == nil{

            if FIRAuth.auth()!.currentUser!.isEmailVerified{

                let feedVCScene = self.navigationController?.storyboard?.instantiateViewController(withIdentifier: "ViewControllerVC_ID") as! ViewController
                self.verificationTimer.invalidate()     //Kill the timer
                self.navigationController?.pushViewController(feedVCScene, animated: true)
                // Segueing to the next view(i prefer the instantiation method).
            } else {

                print("It aint verified yet")

            }
        } else {

            print(err?.localizedDescription)

        }
    })

}

答案 1 :(得分:1)

我的方法是添加NSNotification.Name.UIApplicationDidBecomeActive,因为用户必须离开应用以验证电子邮件:

NotificationCenter.default.addObserver(self,selector:#selector(APEmailVerificationViewController.checkEmailVerificationState),name:NSNotification.Name.UIApplicationDidBecomeActive, object:  nil)

不要忘记删除viewDidDisappear中的通知。这是APEmailVerificationViewController.checkEmailVerificationState func:

FIRAuth.auth()?.currentUser?.reload(completion: { [unowned self] (error) in
        if error != nil {
            print(error!.localizedDescription)
            return
        }
        if !FIRAuth.auth()!.currentUser!.isEmailVerified {
            return
        }

        /**
            Great! We go the playground of the app.
         */
        UIAlertView(title: "Hooray", message: "You've successfully verified your email", delegate: nil, cancelButtonTitle: "Ok").show()
        APIntent.gotoPlayground()
    })

希望它有所帮助!