@@ -370,19 +370,21 @@ - (NSString *)stringBySha256HashingString:(NSString *)input {
370
370
371
371
static void handleSignInWithApple (FLTFirebaseAuthPlugin *object, FIRAuthDataResult *authResult,
372
372
NSString *authorizationCode, NSError *error) {
373
+ void (^completion)(PigeonUserCredential *_Nullable, FlutterError *_Nullable) =
374
+ object.appleCompletion ;
375
+ if (completion == nil ) return ;
376
+
373
377
if (error != nil ) {
374
378
if (error.code == FIRAuthErrorCodeSecondFactorRequired) {
375
- [object handleMultiFactorError: object.appleArguments
376
- completion: object.appleCompletion
377
- withError: error];
379
+ [object handleMultiFactorError: object.appleArguments completion: completion withError: error];
378
380
} else {
379
- object. appleCompletion (nil , [FLTFirebaseAuthPlugin convertToFlutterError: error]);
381
+ completion (nil , [FLTFirebaseAuthPlugin convertToFlutterError: error]);
380
382
}
381
383
return ;
382
384
}
383
- object. appleCompletion ([PigeonParser getPigeonUserCredentialFromAuthResult: authResult
384
- authorizationCode: authorizationCode],
385
- nil );
385
+ completion ([PigeonParser getPigeonUserCredentialFromAuthResult: authResult
386
+ authorizationCode: authorizationCode],
387
+ nil );
386
388
}
387
389
388
390
- (void )authorizationController : (ASAuthorizationController *)controller
@@ -418,6 +420,8 @@ - (void)authorizationController:(ASAuthorizationController *)controller
418
420
419
421
if (self.isReauthenticatingWithApple == YES ) {
420
422
self.isReauthenticatingWithApple = NO ;
423
+ void (^capturedCompletion)(PigeonUserCredential *_Nullable, FlutterError *_Nullable) =
424
+ self.appleCompletion ;
421
425
[[FIRAuth.auth currentUser ]
422
426
reauthenticateWithCredential: credential
423
427
completion: ^(FIRAuthDataResult *_Nullable authResult,
@@ -426,16 +430,20 @@ - (void)authorizationController:(ASAuthorizationController *)controller
426
430
}];
427
431
428
432
} else if (self.linkWithAppleUser != nil ) {
429
- [self .linkWithAppleUser
430
- linkWithCredential: credential
431
- completion: ^(FIRAuthDataResult *authResult, NSError *error) {
432
- self.linkWithAppleUser = nil ;
433
- handleSignInWithApple (self, authResult, authorizationCode, error);
434
- }];
433
+ FIRUser *userToLink = self.linkWithAppleUser ;
434
+ void (^capturedCompletion)(PigeonUserCredential *_Nullable, FlutterError *_Nullable) =
435
+ self.appleCompletion ;
436
+ [userToLink linkWithCredential: credential
437
+ completion: ^(FIRAuthDataResult *authResult, NSError *error) {
438
+ self.linkWithAppleUser = nil ;
439
+ handleSignInWithApple (self, authResult, authorizationCode, error);
440
+ }];
435
441
436
442
} else {
437
443
FIRAuth *signInAuth =
438
444
self.signInWithAppleAuth != nil ? self.signInWithAppleAuth : FIRAuth.auth ;
445
+ void (^capturedCompletion)(PigeonUserCredential *_Nullable, FlutterError *_Nullable) =
446
+ self.appleCompletion ;
439
447
[signInAuth signInWithCredential: credential
440
448
completion: ^(FIRAuthDataResult *_Nullable authResult,
441
449
NSError *_Nullable error) {
@@ -468,7 +476,7 @@ - (void)authorizationController:(ASAuthorizationController *)controller
468
476
case ASAuthorizationErrorNotHandled:
469
477
self.appleCompletion (nil ,
470
478
[FlutterError errorWithCode: @" not-handled"
471
- message: @" The authorization request wasn’ t handled."
479
+ message: @" The authorization request wasn' t handled."
472
480
details: nil ]);
473
481
break ;
474
482
0 commit comments