From 64b01307b299e5c0e6823dd8c254e05fee1d4da9 Mon Sep 17 00:00:00 2001 From: YuryR Date: Thu, 21 Sep 2017 18:25:52 -0700 Subject: [PATCH 1/3] Adding temporary workaround to call FirebaseAuth completion block in the main thread. --- .../FUIPhoneEntryViewController.m | 46 +++++++++++-------- .../FUIPhoneVerificationViewController.m | 44 ++++++++++-------- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m b/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m index e416f760578..6346a2ddedc 100644 --- a/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m +++ b/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m @@ -168,28 +168,36 @@ - (void)onNext:(NSString *)phoneNumber { [provider verifyPhoneNumber:phoneNumberWithCountryCode UIDelegate:self completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { + // Temporary fix to guarantee execution of the completion block in the main thread. + // TODO: Remove temporary workaround when the issue is fixed in FirebaseAuth. + dispatch_block_t completionBlock = ^() { + [self decrementActivity]; + self.navigationItem.rightBarButtonItem.enabled = YES; + + if (error) { + [_phoneNumberField becomeFirstResponder]; + + UIAlertController *alertController = [FUIPhoneAuth alertControllerForError:error + actionHandler:nil]; + [self presentViewController:alertController animated:YES completion:nil]; + + FUIPhoneAuth *delegate = [self.authUI providerWithID:FIRPhoneAuthProviderID]; + [delegate callbackWithCredential:nil error:error result:nil]; + return; + } - [self decrementActivity]; - self.navigationItem.rightBarButtonItem.enabled = YES; - - if (error) { - [_phoneNumberField becomeFirstResponder]; + UIViewController *controller = + [[FUIPhoneVerificationViewController alloc] initWithAuthUI:self.authUI + verificationID:verificationID + phoneNumber:phoneNumberWithCountryCode]; - UIAlertController *alertController = [FUIPhoneAuth alertControllerForError:error - actionHandler:nil]; - [self presentViewController:alertController animated:YES completion:nil]; - - FUIPhoneAuth *delegate = [self.authUI providerWithID:FIRPhoneAuthProviderID]; - [delegate callbackWithCredential:nil error:error result:nil]; - return; + [self pushViewController:controller]; + }; + if ([NSThread isMainThread]) { + completionBlock(); + } else { + dispatch_sync(dispatch_get_main_queue(), completionBlock); } - - UIViewController *controller = - [[FUIPhoneVerificationViewController alloc] initWithAuthUI:self.authUI - verificationID:verificationID - phoneNumber:phoneNumberWithCountryCode]; - - [self pushViewController:controller]; }]; } diff --git a/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m b/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m index 8eb632a2751..467283ac57b 100644 --- a/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m +++ b/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m @@ -138,25 +138,33 @@ - (IBAction)onResendCode:(id)sender { [provider verifyPhoneNumber:_phoneNumber UIDelegate:self completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { - - [self decrementActivity]; - _verificationID = verificationID; - [_codeField becomeFirstResponder]; - - if (error) { - UIAlertController *alertController = [FUIPhoneAuth alertControllerForError:error - actionHandler:^{ - [_codeField clearCodeInput]; - [_codeField becomeFirstResponder]; - }]; - [self presentViewController:alertController animated:YES completion:nil]; - return; + // Temporary fix to guarantee execution of the completion block in the main thread. + // TODO: Remove temporary workaround when the issue is fixed in FirebaseAuth. + dispatch_block_t completionBlock = ^() { + [self decrementActivity]; + _verificationID = verificationID; + [_codeField becomeFirstResponder]; + + if (error) { + UIAlertController *alertController = [FUIPhoneAuth alertControllerForError:error + actionHandler:^{ + [_codeField clearCodeInput]; + [_codeField becomeFirstResponder]; + }]; + [self presentViewController:alertController animated:YES completion:nil]; + return; + } + + NSString *resultMessage = + [NSString stringWithFormat:FUIPhoneAuthLocalizedString(kPAStr_ResendCodeResult), + _phoneNumber]; + [self showAlertWithMessage:resultMessage]; + }; + if ([NSThread isMainThread]) { + completionBlock(); + } else { + dispatch_sync(dispatch_get_main_queue(), completionBlock); } - - NSString *resultMessage = - [NSString stringWithFormat:FUIPhoneAuthLocalizedString(kPAStr_ResendCodeResult), - _phoneNumber]; - [self showAlertWithMessage:resultMessage]; }]; } - (IBAction)onPhoneNumberSelected:(id)sender { From 9520856eddbc9736915ef21c1d6ef81e7bab4956 Mon Sep 17 00:00:00 2001 From: YuryR Date: Thu, 21 Sep 2017 18:39:34 -0700 Subject: [PATCH 2/3] Fix spelling typo in the comment. --- FirebasePhoneAuthUI/FUIPhoneEntryViewController.m | 2 +- FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m b/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m index 6346a2ddedc..5d0eb07ea8f 100644 --- a/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m +++ b/FirebasePhoneAuthUI/FUIPhoneEntryViewController.m @@ -168,7 +168,7 @@ - (void)onNext:(NSString *)phoneNumber { [provider verifyPhoneNumber:phoneNumberWithCountryCode UIDelegate:self completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { - // Temporary fix to guarantee execution of the completion block in the main thread. + // Temporary fix to guarantee execution of the completion block on the main thread. // TODO: Remove temporary workaround when the issue is fixed in FirebaseAuth. dispatch_block_t completionBlock = ^() { [self decrementActivity]; diff --git a/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m b/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m index 467283ac57b..845fa53262c 100644 --- a/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m +++ b/FirebasePhoneAuthUI/FUIPhoneVerificationViewController.m @@ -138,7 +138,7 @@ - (IBAction)onResendCode:(id)sender { [provider verifyPhoneNumber:_phoneNumber UIDelegate:self completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { - // Temporary fix to guarantee execution of the completion block in the main thread. + // Temporary fix to guarantee execution of the completion block on the main thread. // TODO: Remove temporary workaround when the issue is fixed in FirebaseAuth. dispatch_block_t completionBlock = ^() { [self decrementActivity]; From 3b4e669d7feed24d125d1bc584adbece0fbeadb2 Mon Sep 17 00:00:00 2001 From: YuryR Date: Fri, 22 Sep 2017 12:20:09 -0700 Subject: [PATCH 3/3] Increase min required version of FirebaseAuth to 4.2 --- FirebaseUI_dev_auth.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseUI_dev_auth.podspec b/FirebaseUI_dev_auth.podspec index 5d622107068..3c310ed2b81 100644 --- a/FirebaseUI_dev_auth.podspec +++ b/FirebaseUI_dev_auth.podspec @@ -20,7 +20,7 @@ Pod::Spec.new do |s| 'FirebaseAuthUI/**/*.xib'] } authbase.dependency 'Firebase/Analytics' - authbase.dependency 'FirebaseAuth' + authbase.dependency 'FirebaseAuth', '~> 4.2' end end