ios - Firebase 从异步调用返回 bool 值

标签 ios swift firebase firebase-authentication

我正在尝试让 firebase fetchProvidersForEmail 在完成闭包之外设置一个 bool 值,但我不确定该怎么做,因为请求是异步的。这就是我所拥有的:

FIRAuth.auth()?.fetchProvidersForEmail(emailSignUpTextField.text!, completion:{(providers, error) in
        if error != nil{
            print(error)

            if error!.code == FIRAuthErrorCode.ErrorCodeInvalidEmail.rawValue{
                self.showErrorAlert("Invalid Email", msg: "Please input a valid email.")
            }
        }
        else{
            //If there are no errors and there are providers, the email exists
            if providers != nil{
                self.showErrorAlert("Email in Use", msg: "There is already an account   created with that email.")
            }
            //The email does not exist
            else{
                self.segueBool = true          
                print("it works")
            }
        }
    })

如果没有错误,我需要将 self.segueBool 设置为 true。任何帮助将不胜感激。

最佳答案

您可以使用该 bool 值设置全局最终/静态变量, 并在 firebase 回调之前为该变量创建一个监听器(这将帮助您表现得像“同步”)

这样,当设置变量时,您可以处理更改。

关于ios - Firebase 从异步调用返回 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38218191/

相关文章:

ios - 选择器 'datePicker' 没有已知的类方法

ios - 隐藏和显示状态栏时状态栏闪烁

ios - 理解MongoDB最简单的方法iphone

ios - 如何将我的 iOS 应用程序中的内容分享到 BBM?

ios - 这是在闭包中使用 weak self 的正确位置吗?

java - Firebase 值未更新

android - 在Android中使用firebase通过ID查找对象的方法

android - 图片上传后如何获取图片下载地址

ios - 用于编辑和非编辑文本字段的不同弹出窗口

arrays - 使用数组 Swift SpriteKit 生成多个硬币节点