Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift Firebase:发送电子邮件后如何检查用户是否已验证?_Ios_Swift_Firebase_Firebase Authentication - Fatal编程技术网

Ios Swift Firebase:发送电子邮件后如何检查用户是否已验证?

Ios Swift Firebase:发送电子邮件后如何检查用户是否已验证?,ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,创建帐户后,我发送了一封带有验证链接的电子邮件: func sendVerificationMail() { if self.authUser != nil && !self.authUser!.isEmailVerified { self.authUser!.sendEmailVerification(completion: { (error) in // TODO Notify user email w

创建帐户后,我发送了一封带有验证链接的电子邮件:

func sendVerificationMail() {
        if self.authUser != nil && !self.authUser!.isEmailVerified {
            self.authUser!.sendEmailVerification(completion: { (error) in

                // TODO Notify user email was sent or not because of error

            })
        } else {

            // TODO Notify everything is OK

        }
    }
在另一个地方,我检查确认:

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        if Auth.auth().currentUser != nil && Auth.auth().currentUser!.isEmailVerified {
            self.performSegue(withIdentifier: "toMainScreen", sender: self)
        } else {
            self.performSegue(withIdentifier: "notLoggedView", sender: self)
        }
    }

即使确认了,我也总是去NotlogeDview。有人可以解释原因吗?

我遇到过类似的问题,要解决它,我必须重新加载配置文件。试试这个

func loginUser() {

       Auth.auth().currentUser?.reload(completion: { (error) in

                  if let error = error {
                            print(error)
                  } else {
                          if Auth.auth().currentUser != nil && Auth.auth().currentUser!.isEmailVerified {
                             self.performSegue(withIdentifier: "toMainScreen", sender: self)
                          } else {
                                  self.performSegue(withIdentifier: "notLoggedView", sender: self).  
                               }
                         }
                 })
}
另外,每次可以将
Auth.Auth().currentUser
存储在
变量中时,都要编写
Auth.Auth().currentUser
。而且,您可以在任何地方使用此功能

if let authUser = Auth.auth().currentUser { //You can also get  current user like this in a safe way
  //Do your stuff here
}

您是否已检查isEmailVerified的值?你验证过电子邮件了吗?@jawadAli I在viewdid中检查它,并在if中显示函数。是的,我也单击了链接。所以Auth.Auth().currentUser!。即使您验证电子邮件,isEmailVerified也为false?@jawadAli yes:/在使用电子邮件验证对部分进行评论后,它工作正常。
isEmailVerified
仅在用户从服务器获得新的ID令牌后才会更新。因此,这可能是当你重新启动应用程序时,当你重新启动时,或当令牌刷新时(每小时发生一次)。@Yardi Anytime!一点建议,如果用户未登录,此代码会导致错误,在重新加载之前,您需要将if currentUser!=这就是为什么我建议安全展开-->
如果让authUser=Auth.Auth().currentUser{//你也可以用安全的方式得到这样的当前用户//在这里做你的事情}