429
429
static NSString *const kAutoAccountLinking = @" Link with Google" ;
430
430
431
431
/* * @var kAutoPhoneNumberSignIn
432
- @brief The button title for automated account linking .
432
+ @brief The button title for automated Phone Number sign-in .
433
433
*/
434
434
static NSString *const kAutoPhoneNumberSignIn = @" Sign in With Phone Number" ;
435
435
@@ -676,16 +676,16 @@ - (void)updateTable {
676
676
]],
677
677
[StaticContentTableViewSection sectionWithTitle: kPhoneAuthSectionTitle cells: @[
678
678
[StaticContentTableViewCell cellWithTitle: kPhoneNumberSignInReCaptchaTitle
679
- action: ^{ [weakSelf signInWithPhoneNumberRecaptcha ]; }],
679
+ action: ^{ [weakSelf signInWithPhoneNumberPrompt ]; }],
680
680
[StaticContentTableViewCell cellWithTitle: kPhoneNumberSignInTitle
681
681
action: ^{ [weakSelf signInWithPhoneNumber ]; }],
682
682
[StaticContentTableViewCell cellWithTitle: kUpdatePhoneNumber
683
- action: ^{ [weakSelf updatePhoneNumber ]; }],
683
+ action: ^{ [weakSelf updatePhoneNumberPrompt ]; }],
684
684
[StaticContentTableViewCell cellWithTitle: kLinkPhoneNumber
685
- action: ^{ [weakSelf linkPhoneNumber ]; }],
685
+ action: ^{ [weakSelf linkPhoneNumberPrompt ]; }],
686
686
[StaticContentTableViewCell cellWithTitle: kUnlinkPhoneNumber
687
687
action: ^{
688
- [weakSelf unlinkFromProvider: FIRPhoneAuthProviderID completion: nil ];
688
+ [weakSelf unlinkFromProvider: FIRPhoneAuthProviderID completion: nil ];
689
689
}],
690
690
]],
691
691
[StaticContentTableViewSection sectionWithTitle: kSectionTitleSignIn cells: @[
@@ -1053,28 +1053,28 @@ - (void)automatedPhoneNumberSignIn {
1053
1053
[self log: @" INITIATING AUTOMATED MANUAL TEST FOR PHONE NUMBER SIGN IN:" ];
1054
1054
[self commonPhoneNumberInputWithTitle: @" Phone for automation"
1055
1055
Completion: ^(NSString *_Nullable phone) {
1056
- [self signInWithPhoneNumberRecaptchaWithString : phone completion: ^(NSError *error){
1056
+ [self signInWithPhoneNumber : phone completion: ^(NSError *error) {
1057
1057
if (error) {
1058
1058
[self logFailedTest: @" Could not sign in with phone number reCAPTCHA." ];
1059
1059
}
1060
1060
[self logSuccess: @" sign-in with phone number reCAPTCHA test succeeded." ];
1061
1061
[auth signOut: NULL ];
1062
- [self signInWithPhoneNumberRecaptchaWithString : phone completion: ^(NSError *error){
1062
+ [self signInWithPhoneNumber : phone completion: ^(NSError *error) {
1063
1063
if (error) {
1064
1064
[self logFailedTest: @" Could not sign in with phone number reCAPTCHA." ];
1065
1065
}
1066
1066
[self logSuccess: @" second sign-in with phone number reCAPTCHA test succeeded." ];
1067
- [self updatePhoneNumberWithString : phone completion: ^{
1067
+ [self updatePhoneNumber : phone completion: ^( NSError *error) {
1068
1068
if (error) {
1069
1069
[self logFailedTest: @" Could not update phone number." ];
1070
1070
}
1071
1071
[self logSuccess: @" update phone number test succeeded." ];
1072
- [self unlinkFromProvider: FIRPhoneAuthProviderID completion: ^ {
1072
+ [self unlinkFromProvider: FIRPhoneAuthProviderID completion: ^( NSError *error) {
1073
1073
if (error) {
1074
1074
[self logFailedTest: @" Could not unlink phone number." ];
1075
1075
}
1076
1076
[self logSuccess: @" unlink phone number test succeeded." ];
1077
- [self linkPhoneNumberWithString : phone completion: ^{
1077
+ [self linkPhoneNumber : phone completion: ^( NSError *error) {
1078
1078
if (error) {
1079
1079
[self logFailedTest: @" Could not link phone number." ];
1080
1080
}
@@ -2106,16 +2106,21 @@ - (void)showEmailPasswordDialogWithCompletion:(ShowEmailPasswordDialogCompletion
2106
2106
/* * @fn unlinkFromProvider:
2107
2107
@brief Unlinks the current user from the provider with the specified provider ID.
2108
2108
@param provider The provider ID of the provider to unlink the current user's account from.
2109
+ @completion A completion block to be executed after the provider is unlinked.
2109
2110
*/
2110
- - (void )unlinkFromProvider : (NSString *)provider completion : (void (^)(void ))completion {
2111
+ - (void )unlinkFromProvider : (NSString *)provider
2112
+ completion : (void (^)(NSError *_Nullable))completion {
2111
2113
[[self user ] unlinkFromProvider: provider
2112
2114
completion: ^(FIRUser *_Nullable user,
2113
2115
NSError *_Nullable error) {
2114
2116
if (error) {
2115
2117
[self logFailure: @" unlink auth provider failed" error: error];
2118
+ completion (error);
2116
2119
} else {
2117
2120
[self logSuccess: @" unlink auth provider succeeded." ];
2118
- if (completion) completion ();
2121
+ if (completion) {
2122
+ completion (nil );
2123
+ }
2119
2124
}
2120
2125
[self showTypicalUIForUserUpdateResultsWithTitle: kUnlinkTitle error: error];
2121
2126
}];
@@ -2516,12 +2521,13 @@ - (void)signInWithPhoneNumber {
2516
2521
}];
2517
2522
}
2518
2523
2519
- /* * @fn signInWithPhoneNumberRecaptchaWithString
2520
- @brief Allows sign in with phone number using reCAPTCHA and completion.
2521
- @param phoneNumber Number pass in string for automation.
2524
+ /* * @fn signInWithPhoneNumber
2525
+ @brief Allows sign in with phone number using reCAPTCHA.
2526
+ @param phoneNumber Number pass in string.
2527
+ @completion A completion block to be executed after successful phone number sign in.
2522
2528
*/
2523
- - (void )signInWithPhoneNumberRecaptchaWithString : (NSString *_Nullable)phoneNumber
2524
- completion : (void (^)(NSError *_Nullable))completion {
2529
+ - (void )signInWithPhoneNumber : (NSString *_Nullable)phoneNumber
2530
+ completion : (void (^)(NSError *_Nullable))completion {
2525
2531
[self showSpinner: ^{
2526
2532
[[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2527
2533
UIDelegate: nil
@@ -2531,26 +2537,30 @@ - (void)signInWithPhoneNumberRecaptchaWithString:(NSString *_Nullable)phoneNumbe
2531
2537
if (error) {
2532
2538
[self logFailure: @" failed to send verification code" error: error];
2533
2539
[self showMessagePrompt: error.localizedDescription];
2540
+ completion (error);
2534
2541
return ;
2535
2542
}
2536
2543
[self logSuccess: @" Code sent" ];
2537
2544
[self commonPhoneNumberInputWithTitle: @" Code"
2538
2545
Completion: ^(NSString *_Nullable verificationCode) {
2539
2546
[self commontPhoneVerificationWithVerificationID: verificationID
2540
2547
verificationCode: verificationCode];
2541
- if (completion) completion (nil );
2548
+ if (completion) {
2549
+ completion (nil );
2550
+ }
2542
2551
}];
2543
2552
}];
2544
2553
}];
2545
2554
}];
2546
2555
}
2547
2556
2548
- /* * @fn signInWithPhoneNumberRecaptcha
2549
- @brief Allows sign in with phone number using reCAPTCHA
2557
+ /* * @fn signInWithPhoneNumberPrompt
2558
+ @brief Allows sign in with phone number via popup prompt.
2550
2559
*/
2551
- - (void )signInWithPhoneNumberRecaptcha {
2552
- [self commonPhoneNumberInputWithTitle: @" Phone #" Completion: ^(NSString *_Nullable phone) {
2553
- [self signInWithPhoneNumberRecaptchaWithString: (phone) completion: nil ];
2560
+ - (void )signInWithPhoneNumberPrompt {
2561
+ [self commonPhoneNumberInputWithTitle: @" Phone #"
2562
+ Completion: ^(NSString *_Nullable phone) {
2563
+ [self signInWithPhoneNumber: phone completion: nil ];
2554
2564
}];
2555
2565
}
2556
2566
@@ -2594,12 +2604,13 @@ - (void)commontPhoneVerificationWithVerificationID:(NSString *)verificationID
2594
2604
}];
2595
2605
}
2596
2606
2597
- /* * @fn updatePhoneNumberWithString
2607
+ /* * @fn updatePhoneNumber
2598
2608
@brief Allows adding a verified phone number to the currently signed user.
2599
- @param phoneNumber Number pass in string for automation.
2609
+ @param phoneNumber Number pass in string.
2610
+ @completion A completion block to be executed after phone number is updated.
2600
2611
*/
2601
- - (void )updatePhoneNumberWithString : (NSString *_Nullable)phoneNumber
2602
- completion : (void (^)(void ))completion {
2612
+ - (void )updatePhoneNumber : (NSString *_Nullable)phoneNumber
2613
+ completion : (void (^)(NSError *_Nullable ))completion {
2603
2614
[self showSpinner: ^{
2604
2615
[[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2605
2616
UIDelegate: nil
@@ -2608,6 +2619,7 @@ - (void)updatePhoneNumberWithString:(NSString *_Nullable)phoneNumber
2608
2619
if (error) {
2609
2620
[self logFailure: @" failed to send verification code" error: error];
2610
2621
[self showMessagePrompt: error.localizedDescription];
2622
+ completion (error);
2611
2623
return ;
2612
2624
}
2613
2625
[self logSuccess: @" Code sent" ];
@@ -2628,9 +2640,12 @@ - (void)updatePhoneNumberWithString:(NSString *_Nullable)phoneNumber
2628
2640
if (error) {
2629
2641
[self logFailure: @" update phone number failed" error: error];
2630
2642
[self showMessagePrompt: error.localizedDescription];
2643
+ completion (error);
2631
2644
} else {
2632
2645
[self logSuccess: @" update phone number succeeded." ];
2633
- if (completion) completion ();
2646
+ if (completion) {
2647
+ completion (nil );
2648
+ }
2634
2649
}
2635
2650
}];
2636
2651
}];
@@ -2645,107 +2660,113 @@ - (void)updatePhoneNumberWithString:(NSString *_Nullable)phoneNumber
2645
2660
/* * @fn updatePhoneNumber
2646
2661
@brief Allows adding a verified phone number to the currently signed user via popup prompt.
2647
2662
*/
2648
- - (void )updatePhoneNumber {
2663
+ - (void )updatePhoneNumberPrompt {
2649
2664
[self showTextInputPromptWithMessage: @" Update Phone #:"
2650
2665
keyboardType: UIKeyboardTypePhonePad
2651
2666
completionBlock: ^(BOOL userPressedOK, NSString *_Nullable phoneNumber) {
2652
2667
if (!userPressedOK || !phoneNumber.length ) {
2653
2668
return ;
2654
2669
}
2655
- [self updatePhoneNumberWithString : phoneNumber completion: nil ];
2670
+ [self updatePhoneNumber : phoneNumber completion: nil ];
2656
2671
}];
2657
2672
}
2658
2673
2659
- /* * @fn linkPhoneNumberWithString
2674
+ /* * @fn linkPhoneNumber
2660
2675
@brief Allows linking a verified phone number to the currently signed user.
2661
- @param phoneNumber Number pass in string for automation.
2676
+ @param phoneNumber Number pass in string.
2677
+ @completion A completion block to be executed after linking phone number.
2662
2678
*/
2663
- - (void )linkPhoneNumberWithString : (NSString *_Nullable)phoneNumber
2664
- completion : (void (^)(void ))completion {
2665
- [self showSpinner: ^{
2666
- [[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2667
- UIDelegate: nil
2668
- completion: ^(NSString *_Nullable verificationID,
2669
- NSError *_Nullable error) {
2670
- [self hideSpinner: ^{
2671
- if (error) {
2672
- [self logFailure: @" failed to send verification code" error: error];
2673
- [self showMessagePrompt: error.localizedDescription];
2679
+ - (void )linkPhoneNumber : (NSString *_Nullable)phoneNumber
2680
+ completion : (void (^)(NSError *_Nullable))completion {
2681
+ [self showSpinner: ^{
2682
+ [[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2683
+ UIDelegate: nil
2684
+ completion: ^(NSString *_Nullable verificationID,
2685
+ NSError *_Nullable error) {
2686
+ [self hideSpinner: ^{
2687
+ if (error) {
2688
+ [self logFailure: @" failed to send verification code" error: error];
2689
+ [self showMessagePrompt: error.localizedDescription];
2690
+ completion (error);
2691
+ return ;
2692
+ }
2693
+ [self logSuccess: @" Code sent" ];
2694
+
2695
+ [self showTextInputPromptWithMessage: @" Verification code:"
2696
+ keyboardType: UIKeyboardTypeNumberPad
2697
+ completionBlock: ^(BOOL userPressedOK,
2698
+ NSString *_Nullable verificationCode) {
2699
+ if (!userPressedOK || !verificationCode.length ) {
2674
2700
return ;
2675
2701
}
2676
- [self logSuccess: @" Code sent" ];
2677
-
2678
- [self showTextInputPromptWithMessage: @" Verification code:"
2679
- keyboardType: UIKeyboardTypeNumberPad
2680
- completionBlock: ^(BOOL userPressedOK,
2681
- NSString *_Nullable verificationCode) {
2682
- if (!userPressedOK || !verificationCode.length ) {
2683
- return ;
2684
- }
2685
- [self showSpinner: ^{
2686
- FIRPhoneAuthCredential *credential =
2687
- [[AppManager phoneAuthProvider ] credentialWithVerificationID: verificationID
2688
- verificationCode: verificationCode];
2689
- [[self user ] linkWithCredential: credential
2690
- completion: ^(FIRUser *_Nullable user,
2691
- NSError *_Nullable error) {
2692
- [self hideSpinner: ^{
2693
- if (error) {
2694
- if (error.code == FIRAuthErrorCodeCredentialAlreadyInUse) {
2695
- [self showMessagePromptWithTitle: @" Phone number is already linked to "
2696
- @" another user"
2697
- message: @" Tap Ok to sign in with that user now."
2698
- showCancelButton: YES
2699
- completion: ^(BOOL userPressedOK,
2700
- NSString *_Nullable userInput) {
2701
- if (userPressedOK) {
2702
- // If FIRAuthErrorCodeCredentialAlreadyInUse error, sign in with the
2703
- // provided credential.
2704
- [self showSpinner: ^{
2705
- FIRPhoneAuthCredential *credential =
2706
- error.userInfo [FIRAuthUpdatedCredentialKey];
2707
- [[AppManager auth ] signInWithCredential: credential
2708
- completion: ^(FIRUser *_Nullable user,
2709
- NSError *_Nullable error) {
2710
- [self hideSpinner: ^{
2711
- if (error) {
2712
- [self logFailure: @" failed to verify phone number" error: error];
2713
- [self showMessagePrompt: error.localizedDescription];
2714
- return ;
2715
- }
2716
- }];
2702
+ [self showSpinner: ^{
2703
+ FIRPhoneAuthCredential *credential =
2704
+ [[AppManager phoneAuthProvider ] credentialWithVerificationID: verificationID
2705
+ verificationCode: verificationCode];
2706
+ [[self user ] linkWithCredential: credential
2707
+ completion: ^(FIRUser *_Nullable user,
2708
+ NSError *_Nullable error) {
2709
+ [self hideSpinner: ^{
2710
+ if (error) {
2711
+ if (error.code == FIRAuthErrorCodeCredentialAlreadyInUse) {
2712
+ [self showMessagePromptWithTitle: @" Phone number is already linked to "
2713
+ @" another user"
2714
+ message: @" Tap Ok to sign in with that user now."
2715
+ showCancelButton: YES
2716
+ completion: ^(BOOL userPressedOK,
2717
+ NSString *_Nullable userInput) {
2718
+ if (userPressedOK) {
2719
+ // If FIRAuthErrorCodeCredentialAlreadyInUse error, sign in with the
2720
+ // provided credential.
2721
+ [self showSpinner: ^{
2722
+ FIRPhoneAuthCredential *credential =
2723
+ error.userInfo [FIRAuthUpdatedCredentialKey];
2724
+ [[AppManager auth ] signInWithCredential: credential
2725
+ completion: ^(FIRUser *_Nullable user,
2726
+ NSError *_Nullable error) {
2727
+ [self hideSpinner: ^{
2728
+ if (error) {
2729
+ [self logFailure: @" failed to verify phone number" error: error];
2730
+ [self showMessagePrompt: error.localizedDescription];
2731
+ completion (error);
2732
+ return ;
2733
+ }
2717
2734
}];
2718
2735
}];
2719
- }
2720
- }];
2721
- } else {
2722
- [self logFailure: @" link phone number failed" error: error];
2723
- [self showMessagePrompt: error.localizedDescription];
2724
- }
2725
- return ;
2736
+ }];
2737
+ }
2738
+ }];
2739
+ } else {
2740
+ [self logFailure: @" link phone number failed" error: error];
2741
+ [self showMessagePrompt: error.localizedDescription];
2726
2742
}
2727
- [self logSuccess: @" link phone number succeeded." ];
2728
- if (completion) completion ();
2729
- }];
2743
+ completion (error);
2744
+ return ;
2745
+ }
2746
+ [self logSuccess: @" link phone number succeeded." ];
2747
+ if (completion) {
2748
+ completion (nil );
2749
+ }
2730
2750
}];
2731
2751
}];
2732
2752
}];
2733
2753
}];
2734
2754
}];
2735
2755
}];
2756
+ }];
2736
2757
}
2737
2758
2738
2759
/* * @fn linkPhoneNumber
2739
- @brief Allows linking a verified phone number to the currently signed user.
2760
+ @brief Allows linking a verified phone number to the currently signed user via popup prompt .
2740
2761
*/
2741
- - (void )linkPhoneNumber {
2762
+ - (void )linkPhoneNumberPrompt {
2742
2763
[self showTextInputPromptWithMessage: @" Phone #:"
2743
2764
keyboardType: UIKeyboardTypePhonePad
2744
2765
completionBlock: ^(BOOL userPressedOK, NSString *_Nullable phoneNumber) {
2745
2766
if (!userPressedOK || !phoneNumber.length ) {
2746
2767
return ;
2747
2768
}
2748
- [self linkPhoneNumberWithString : phoneNumber completion: nil ];
2769
+ [self linkPhoneNumber : phoneNumber completion: nil ];
2749
2770
}];
2750
2771
}
2751
2772
0 commit comments