我试图让firebase fetchProvidersForEmail在完成关闭之外设置一个布尔值,但我不确定该请求是如何异步的。这是我的:从异步调用返回布尔值的Firebase
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,如果没有错误。任何帮助,将不胜感激。
您是否在另一个线程中执行此代码?如果没有,完成块应该在完成时捕获结果。在这种情况下它是否是异步并不重要。也许你需要在'if providers!= nil'之后编辑你的else语句来明确地检查你想要的结果。 – cdslijngard
你的问题是什么?你想同步执行这个请求吗? – kelin
是的,我希望这表现同步。 – Pikachu