我試圖讓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