-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix container instantiation timing, IID startup. #4030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fbab379
Fix container instantiation timing, IID startup.
ryanwilson 183cd74
Typo
ryanwilson 8fc1b0e
Further work on instantiation timing.
ryanwilson b909054
Revert unintentional formatting of entire FIRMessaging file.
ryanwilson 9e26c95
Fix tests.
ryanwilson 459f0f8
Format InstanceID.m
ryanwilson a739b23
Remove unused import.
ryanwilson f7931a2
Fix ComponentContainer test.
ryanwilson a7820c4
Minor PR feedback.
ryanwilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| #import <FirebaseCore/FIRLibrary.h> | ||
| #import <FirebaseCore/FIROptions.h> | ||
| #import <GoogleUtilities/GULAppEnvironmentUtil.h> | ||
| #import <GoogleUtilities/GULUserDefaults.h> | ||
| #import "FIRInstanceID+Private.h" | ||
| #import "FIRInstanceIDAuthService.h" | ||
| #import "FIRInstanceIDCheckinPreferences.h" | ||
|
|
@@ -67,8 +68,8 @@ | |
| static NSString *const kAPSEnvironmentDevelopmentValue = @"development"; | ||
| /// FIRMessaging selector that returns the current FIRMessaging auto init | ||
| /// enabled flag. | ||
| static NSString *const kFIRInstanceIDFCMSelectorAutoInitEnabled = @"isAutoInitEnabled"; | ||
| static NSString *const kFIRInstanceIDFCMSelectorInstance = @"messaging"; | ||
| static NSString *const kFIRInstanceIDFCMSelectorAutoInitEnabled = | ||
| @"isAutoInitEnabledWithUserDefaults:"; | ||
|
|
||
| static NSString *const kFIRInstanceIDAPNSTokenType = @"APNSTokenType"; | ||
| static NSString *const kFIRIIDAppReadyToConfigureSDKNotification = | ||
|
|
@@ -77,8 +78,6 @@ | |
| static NSString *const kFIRIIDErrorDomain = @"com.firebase.instanceid"; | ||
| static NSString *const kFIRIIDServiceInstanceID = @"InstanceID"; | ||
|
|
||
| static NSInteger const kFIRIIDErrorCodeInstanceIDFailed = -121; | ||
|
|
||
| typedef void (^FIRInstanceIDKeyPairHandler)(FIRInstanceIDKeyPair *keyPair, NSError *error); | ||
|
|
||
| /** | ||
|
|
@@ -639,41 +638,41 @@ + (void)load { | |
| + (nonnull NSArray<FIRComponent *> *)componentsToRegister { | ||
| FIRComponentCreationBlock creationBlock = | ||
| ^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) { | ||
| // InstanceID only works with the default app. | ||
| if (!container.app.isDefaultApp) { | ||
| // Only configure for the default FIRApp. | ||
| FIRInstanceIDLoggerDebug(kFIRInstanceIDMessageCodeFIRApp002, | ||
| @"Firebase Instance ID only works with the default app."); | ||
| return nil; | ||
| } | ||
|
|
||
| // Ensure it's cached so it returns the same instance every time instanceID is called. | ||
| *isCacheable = YES; | ||
| FIRInstanceID *instanceID = [[FIRInstanceID alloc] initPrivately]; | ||
| [instanceID start]; | ||
| [instanceID configureInstanceIDWithOptions:container.app.options]; | ||
| return instanceID; | ||
| }; | ||
| FIRComponent *instanceIDProvider = | ||
| [FIRComponent componentWithProtocol:@protocol(FIRInstanceIDInstanceProvider) | ||
| instantiationTiming:FIRInstantiationTimingLazy | ||
| instantiationTiming:FIRInstantiationTimingEagerInDefaultApp | ||
| dependencies:@[] | ||
| creationBlock:creationBlock]; | ||
| return @[ instanceIDProvider ]; | ||
| } | ||
|
|
||
| + (void)configureWithApp:(FIRApp *)app { | ||
| if (!app.isDefaultApp) { | ||
| // Only configure for the default FIRApp. | ||
| FIRInstanceIDLoggerDebug(kFIRInstanceIDMessageCodeFIRApp002, | ||
| @"Firebase Instance ID only works with the default app."); | ||
| return; | ||
| } | ||
| [[FIRInstanceID instanceID] configureInstanceIDWithOptions:app.options app:app]; | ||
| } | ||
|
|
||
| - (void)configureInstanceIDWithOptions:(FIROptions *)options app:(FIRApp *)firApp { | ||
| - (void)configureInstanceIDWithOptions:(FIROptions *)options { | ||
| NSString *GCMSenderID = options.GCMSenderID; | ||
| if (!GCMSenderID.length) { | ||
| FIRInstanceIDLoggerError(kFIRInstanceIDMessageCodeFIRApp000, | ||
| @"Firebase not set up correctly, nil or empty senderID."); | ||
| [FIRInstanceID exitWithReason:@"GCM_SENDER_ID must not be nil or empty." forFirebaseApp:firApp]; | ||
| return; | ||
| [NSException raise:kFIRIIDErrorDomain | ||
| format:@"Could not configure Firebase InstanceID. GCMSenderID must not be nil or " | ||
| @"empty."]; | ||
| } | ||
|
|
||
| self.fcmSenderID = GCMSenderID; | ||
| self.firebaseAppID = firApp.options.googleAppID; | ||
| self.firebaseAppID = options.googleAppID; | ||
|
|
||
| // FCM generates a FCM token during app start for sending push notification to device. | ||
| // This is not needed for app extension. | ||
|
|
@@ -682,26 +681,6 @@ - (void)configureInstanceIDWithOptions:(FIROptions *)options app:(FIRApp *)firAp | |
| } | ||
| } | ||
|
|
||
| + (NSError *)configureErrorWithReason:(nonnull NSString *)reason { | ||
| NSString *description = | ||
| [NSString stringWithFormat:@"Configuration failed for service %@.", kFIRIIDServiceInstanceID]; | ||
| if (!reason.length) { | ||
| reason = @"Unknown reason"; | ||
| } | ||
|
|
||
| NSDictionary *userInfo = | ||
| @{NSLocalizedDescriptionKey : description, NSLocalizedFailureReasonErrorKey : reason}; | ||
|
|
||
| return [NSError errorWithDomain:kFIRIIDErrorDomain | ||
| code:kFIRIIDErrorCodeInstanceIDFailed | ||
| userInfo:userInfo]; | ||
| } | ||
|
|
||
| + (void)exitWithReason:(nonnull NSString *)reason forFirebaseApp:(FIRApp *)firebaseApp { | ||
| [NSException raise:kFIRIIDErrorDomain | ||
| format:@"Could not configure Firebase InstanceID. %@", reason]; | ||
| } | ||
|
|
||
| // This is used to start any operations when we receive FirebaseSDK setup notification | ||
| // from FIRCore. | ||
| - (void)didCompleteConfigure { | ||
|
|
@@ -738,29 +717,20 @@ - (BOOL)isFCMAutoInitEnabled { | |
| return NO; | ||
| } | ||
|
|
||
| // Messaging doesn't have the singleton method, auto init should be enabled since FCM exists. | ||
| SEL instanceSelector = NSSelectorFromString(kFIRInstanceIDFCMSelectorInstance); | ||
| if (![messagingClass respondsToSelector:instanceSelector]) { | ||
| return YES; | ||
| } | ||
|
|
||
| // Get FIRMessaging shared instance. | ||
| IMP messagingInstanceIMP = [messagingClass methodForSelector:instanceSelector]; | ||
| id (*getMessagingInstance)(id, SEL) = (void *)messagingInstanceIMP; | ||
| id messagingInstance = getMessagingInstance(messagingClass, instanceSelector); | ||
|
|
||
| // Messaging doesn't have the property, auto init should be enabled since FCM exists. | ||
| // Messaging doesn't have the class method, auto init should be enabled since FCM exists. | ||
| SEL autoInitSelector = NSSelectorFromString(kFIRInstanceIDFCMSelectorAutoInitEnabled); | ||
| if (![messagingInstance respondsToSelector:autoInitSelector]) { | ||
| if (![messagingClass respondsToSelector:autoInitSelector]) { | ||
| return YES; | ||
| } | ||
|
|
||
| // Get autoInitEnabled method. | ||
| IMP isAutoInitEnabledIMP = [messagingInstance methodForSelector:autoInitSelector]; | ||
| BOOL (*isAutoInitEnabled)(id, SEL) = (BOOL(*)(id, SEL))isAutoInitEnabledIMP; | ||
| // Get the autoInitEnabled class method. | ||
| IMP isAutoInitEnabledIMP = [messagingClass methodForSelector:autoInitSelector]; | ||
| BOOL(*isAutoInitEnabled) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can cast through |
||
| (Class, SEL, GULUserDefaults *) = (BOOL(*)(id, SEL, GULUserDefaults *))isAutoInitEnabledIMP; | ||
|
|
||
| // Check FCM's isAutoInitEnabled property. | ||
| return isAutoInitEnabled(messagingInstance, autoInitSelector); | ||
| return isAutoInitEnabled(messagingClass, autoInitSelector, | ||
| [GULUserDefaults standardUserDefaults]); | ||
| } | ||
|
|
||
| // Actually makes InstanceID instantiate both the IID and Token-related subsystems. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a warning or even an error?
Feel free to ignore--I see that this is just copypasta from the prior state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also a "this code should never be run" so maybe it should be an error, but I'll leave it as is since it was copied from before.