ios - Firebase iOS : Second tap is working properly in login page

标签 ios swift firebase firebase-authentication verification

我决定让它尽可能简单。有人可以解释为什么我的代码第一次点击 Path_4 消息(坏路径),但在第二、第三、第四次点击 Path_2 和 Path3 消息(好路径)?有一些代码:

// Login

    Auth.auth().signIn(withEmail: userEmail, password: userPassword) { [weak self] authResult, error in
        guard self != nil else { return }
    }

    // Check user if verified

    if ( Auth.auth().currentUser != nil ) {
        Auth.auth().currentUser!.reload(completion: { (error) in

            if let error = error {
                self.displayAlertMessage(alertTitle: "1", alertMessage: "Path_1");
                print(error)
            } else {
                if Auth.auth().currentUser!.isEmailVerified {
                    self.displayAlertMessage(alertTitle: "2", alertMessage: "Path_2");
                } else {
                    //TODO Verification page
                    self.displayAlertMessage(alertTitle: "3", alertMessage: "Path_3");
                }
            }
        })
    } else {
        self.displayAlertMessage(alertTitle: "4", alertMessage: "Path_4");
    }

最佳答案

好吧,我尝试了类似的方法,但我认为这不是最好的方法:

   // Login

    Auth.auth().signIn(withEmail: userEmail, password: userPassword) { [weak self] authResult, error in
        guard self != nil else { return }
    }

    // Check user if verified

    DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { // Change `2.0` to the desired number of seconds.
       if ( Auth.auth().currentUser != nil ) {
           Auth.auth().currentUser!.reload(completion: { (error) in

               if let error = error {
                   self.displayAlertMessage(alertTitle: "1", alertMessage: "Path_1");
                   print(error)
               } else {
                   if Auth.auth().currentUser!.isEmailVerified {
                       self.displayAlertMessage(alertTitle: "2", alertMessage: "Path_2");
                   } else {
                       //TODO Verification page
                       self.displayAlertMessage(alertTitle: "3", alertMessage: "Path_3");
                   }
               }
           })
       } else {
           self.displayAlertMessage(alertTitle: "4", alertMessage: "Path_4");
       }
    }

我可以做些什么来暂停,直到登录操作尚未完成?

关于ios - Firebase iOS : Second tap is working properly in login page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59973726/

相关文章:

ios - 将 JSON 解析为 TableView 时出现 NSNull 长度错误

android - 我们可以在 Firebase robotest 中编辑 maxDepth 吗?如果是,如何?

ios - 使用 Alamofire 和 SwiftyJSON 正确解析具有多个对象的 JSON 数组

当我设置新字体时,iOS 导航栏不改变颜色

android - Firebase Auth Ui Google 登录 "Developer Error"

node.js - 使用现有密码哈希和盐创建 HMAC

ios - 如何访问类常量和变量

ios - xcodebuild 存档失败,xcode 存档成功

ios - 从包含闭包的 Swift 函数返回值

ios - 在关闭中找不到成员