@@ -496,46 +496,12 @@ - (nullable instancetype)initWithAPIKey:(NSString *)APIKey
496
496
[GULSceneDelegateSwizzler proxyOriginalSceneDelegate ];
497
497
#endif // TARGET_OS_IOS
498
498
499
- #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
500
- static Class applicationClass = nil ;
501
- // iOS App extensions should not call [UIApplication sharedApplication], even if UIApplication
502
- // responds to it.
503
- if (![GULAppEnvironmentUtil isAppExtension ]) {
504
- Class cls = NSClassFromString (@" UIApplication" );
505
- if (cls && [cls respondsToSelector: @selector (sharedApplication )]) {
506
- applicationClass = cls;
507
- }
508
- }
509
- UIApplication *application = [applicationClass sharedApplication ];
510
- if ([application respondsToSelector: @selector (isProtectedDataAvailable )]) {
511
- if ([application isProtectedDataAvailable ]) {
512
- [self protectedDataInitialization ];
513
- } else {
514
- // Add listener for UIApplicationProtectedDataDidBecomeAvailable.
515
- self->_protectedDataDidBecomeAvailableObserver = [[NSNotificationCenter defaultCenter ]
516
- addObserverForName: UIApplicationProtectedDataDidBecomeAvailable
517
- object: nil
518
- queue: nil
519
- usingBlock: ^(NSNotification *notification) {
520
- [self protectedDataInitialization ];
521
- }];
522
- }
523
- } else {
524
- [self protectedDataInitialization ];
525
- }
526
- #else
527
499
[self protectedDataInitialization ];
528
- #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
529
500
}
530
501
return self;
531
502
}
532
503
533
504
- (void )protectedDataInitialization {
534
- #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
535
- [[NSNotificationCenter defaultCenter ] removeObserver: _protectedDataDidBecomeAvailableObserver
536
- name: UIApplicationProtectedDataDidBecomeAvailable
537
- object: nil ];
538
- #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
539
505
// Continue with the rest of initialization in the work thread.
540
506
__weak FIRAuth *weakSelf = self;
541
507
dispatch_async (FIRAuthGlobalWorkQueue (), ^{
@@ -564,17 +530,41 @@ - (void)protectedDataInitialization {
564
530
[strongSelf updateCurrentUser: user byForce: NO savingToDisk: NO error: &error];
565
531
self->_lastNotifiedUserToken = user.rawAccessToken ;
566
532
} else {
533
+ #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
534
+ if (error.code == FIRAuthErrorCodeKeychainError) {
535
+ // If there's a keychain error, assume it is due to the keychain being accessed
536
+ // before the device is unlocked as a result of prewarming, and listen for the
537
+ // UIApplicationProtectedDataDidBecomeAvailable notification.
538
+ [strongSelf addProtectedDataDidBecomeAvailableObserver ];
539
+ }
540
+ #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
567
541
FIRLogError (kFIRLoggerAuth , @" I-AUT000001" ,
568
542
@" Error loading saved user when starting up: %@ " , error);
569
543
}
570
544
} else {
571
545
[strongSelf internalUseUserAccessGroup: storedUserAccessGroup error: &error];
572
546
if (error) {
547
+ #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
548
+ if (error.code == FIRAuthErrorCodeKeychainError) {
549
+ // If there's a keychain error, assume it is due to the keychain being accessed
550
+ // before the device is unlocked as a result of prewarming, and listen for the
551
+ // UIApplicationProtectedDataDidBecomeAvailable notification.
552
+ [strongSelf addProtectedDataDidBecomeAvailableObserver ];
553
+ }
554
+ #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
573
555
FIRLogError (kFIRLoggerAuth , @" I-AUT000001" ,
574
556
@" Error loading saved user when starting up: %@ " , error);
575
557
}
576
558
}
577
559
} else {
560
+ #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
561
+ if (error.code == FIRAuthErrorCodeKeychainError) {
562
+ // If there's a keychain error, assume it is due to the keychain being accessed
563
+ // before the device is unlocked as a result of prewarming, and listen for the
564
+ // UIApplicationProtectedDataDidBecomeAvailable notification.
565
+ [strongSelf addProtectedDataDidBecomeAvailableObserver ];
566
+ }
567
+ #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
578
568
FIRLogError (kFIRLoggerAuth , @" I-AUT000001" , @" Error loading saved user when starting up: %@ " ,
579
569
error);
580
570
}
@@ -613,6 +603,24 @@ - (void)protectedDataInitialization {
613
603
});
614
604
}
615
605
606
+ #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
607
+ - (void )addProtectedDataDidBecomeAvailableObserver {
608
+ __weak FIRAuth *weakSelf = self;
609
+ self->_protectedDataDidBecomeAvailableObserver = [[NSNotificationCenter defaultCenter ]
610
+ addObserverForName: UIApplicationProtectedDataDidBecomeAvailable
611
+ object: nil
612
+ queue: nil
613
+ usingBlock: ^(NSNotification *notification) {
614
+ FIRAuth *strongSelf = weakSelf;
615
+ [[NSNotificationCenter defaultCenter ]
616
+ removeObserver: strongSelf->_protectedDataDidBecomeAvailableObserver
617
+ name: UIApplicationProtectedDataDidBecomeAvailable
618
+ object: nil ];
619
+ [strongSelf protectedDataInitialization ];
620
+ }];
621
+ }
622
+ #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
623
+
616
624
- (void )dealloc {
617
625
@synchronized (self) {
618
626
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter ];
0 commit comments