我正在尝试让 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/