-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add core support with interop for Segmentation SDK. #3430
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
10 commits
Select commit
Hold shift + click to select a range
680b29b
Add core support with interop for Segmentation SDK. Also update heade…
dmandar 96548ea
Review fixes.
dmandar 3a2c367
Minor changes.
dmandar e33e74c
Fix style.
dmandar f24024c
Fix style.
dmandar 9d3d9c4
Style changes.
dmandar a5af315
Fix whitespace in travis.yml
dmandar e9ed408
Fix style.
dmandar e33c5c3
Travis CI is stuck..try updating the travis.yml
dmandar 9944ea1
Undo travis.yml change.
dmandar 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
105 changes: 105 additions & 0 deletions
105
FirebaseSegmentation/Sources/FIRSegmentationComponent.m
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Copyright 2019 Google | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #import "FIRSegmentationComponent.h" | ||
|
|
||
| #import <FirebaseCore/FIRAppInternal.h> | ||
| #import <FirebaseCore/FIRComponentContainer.h> | ||
| #import <FirebaseCore/FIROptionsInternal.h> | ||
| #import "FirebaseSegmentation/Sources/Private/FIRSegmentationInternal.h" | ||
|
|
||
| #ifndef FIRSegmentation_VERSION | ||
| #error "FIRSegmentation_VERSION is not defined: \ | ||
| add -DFIRSegmentation_VERSION=... to the build invocation" | ||
| #endif | ||
|
|
||
| #define STR(x) STR_EXPAND(x) | ||
| #define STR_EXPAND(x) #x | ||
|
|
||
| NSString *const kFirebaseSegmentationErrorDomain = @"com.firebase.segmentation"; | ||
|
|
||
| @implementation FIRSegmentationComponent | ||
|
|
||
| /// Default method for retrieving a Segmentation instance, or creating one if it doesn't exist. | ||
| - (FIRSegmentation *)segmentation { | ||
| // Validate the required information is available. | ||
| FIROptions *options = self.app.options; | ||
| NSString *errorPropertyName; | ||
| if (options.googleAppID.length == 0) { | ||
| errorPropertyName = @"googleAppID"; | ||
| } else if (options.GCMSenderID.length == 0) { | ||
| errorPropertyName = @"GCMSenderID"; | ||
| } | ||
|
|
||
| if (errorPropertyName) { | ||
| [NSException | ||
| raise:kFirebaseSegmentationErrorDomain | ||
| format:@"%@", | ||
| [NSString | ||
| stringWithFormat: | ||
| @"Firebase Segmentation is missing the required %@ property from the " | ||
| @"configured FirebaseApp and will not be able to function properly. Please " | ||
| @"fix this issue to ensure that Firebase is correctly configured.", | ||
| errorPropertyName]]; | ||
| } | ||
|
|
||
| FIRSegmentation *instance = self.segmentationInstance; | ||
| if (!instance) { | ||
| instance = [[FIRSegmentation alloc] initWithAppName:self.app.name FIROptions:self.app.options]; | ||
| self.segmentationInstance = instance; | ||
| } | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
| /// Default initializer. | ||
| - (instancetype)initWithApp:(FIRApp *)app { | ||
| self = [super init]; | ||
| if (self) { | ||
| _app = app; | ||
| _segmentationInstance = nil; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| #pragma mark - Lifecycle | ||
|
|
||
| + (void)load { | ||
| // Register as an internal library to be part of the initialization process. The name comes from | ||
| // go/firebase-sdk-platform-info. | ||
| [FIRApp registerInternalLibrary:self | ||
| withName:@"fire-seg" | ||
| withVersion:[NSString stringWithUTF8String:STR(FIRSegmentation_VERSION)]]; | ||
| } | ||
|
|
||
| #pragma mark - Interoperability | ||
|
|
||
| + (NSArray<FIRComponent *> *)componentsToRegister { | ||
| FIRComponent *segProvider = [FIRComponent | ||
| componentWithProtocol:@protocol(FIRSegmentationProvider) | ||
| instantiationTiming:FIRInstantiationTimingAlwaysEager | ||
| dependencies:@[] | ||
| creationBlock:^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) { | ||
| // Cache the component so instances of Segmentation are cached. | ||
| *isCacheable = YES; | ||
| return [[FIRSegmentationComponent alloc] initWithApp:container.app]; | ||
| }]; | ||
| return @[ segProvider ]; | ||
| } | ||
|
|
||
| @synthesize instances; | ||
|
|
||
| @end |
58 changes: 58 additions & 0 deletions
58
FirebaseSegmentation/Sources/Private/FIRSegmentationComponent.h
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright 2019 Google | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
|
|
||
| #import "FIRLibrary.h" | ||
|
|
||
| @class FIRApp; | ||
| @class FIRSegmentation; | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| /// Provides and creates instances of Segmentation. Used in the | ||
| /// interop registration process to keep track of Segmentation instances for each `FIRApp` instance. | ||
| @protocol FIRSegmentationProvider | ||
|
|
||
| /// Cached instances of Segmentation objects. | ||
| @property(nonatomic, strong) NSMutableDictionary<NSString *, FIRSegmentation *> *instances; | ||
|
|
||
| /// Default method for retrieving a Segmentation instance, or creating one if it doesn't exist. | ||
| - (FIRSegmentation *)segmentation; | ||
|
|
||
| @end | ||
|
|
||
| /// A concrete implementation for FIRSegmentationInterop to create Segmentation instances and | ||
| /// register with Core's component system. | ||
| @interface FIRSegmentationComponent : NSObject <FIRSegmentationProvider, FIRLibrary> | ||
|
|
||
| /// The FIRApp that instances will be set up with. | ||
| @property(nonatomic, weak, readonly) FIRApp *app; | ||
|
|
||
| /// Cached instances of Segmentation objects. | ||
| @property(nonatomic, strong) FIRSegmentation *segmentationInstance; | ||
|
|
||
| /// Default method for retrieving a Segmentation instance, or creating one if it doesn't exist. | ||
| - (FIRSegmentation *)segmentation; | ||
|
|
||
| /// Default initializer. | ||
| - (instancetype)initWithApp:(FIRApp *)app NS_DESIGNATED_INITIALIZER; | ||
|
|
||
| - (instancetype)init __attribute__((unavailable("Use `initWithApp:`."))); | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
30 changes: 30 additions & 0 deletions
30
FirebaseSegmentation/Sources/Private/FIRSegmentationInternal.h
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2019 Google | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @class FIRApp; | ||
|
|
||
| NS_SWIFT_NAME(Segmentation) | ||
| @interface FIRSegmentation : NSObject | ||
|
|
||
| /// Initialize a Segmentation instance with all the required parameters directly. | ||
| - (instancetype)initWithAppName:(NSString *)appName FIROptions:(FIROptions *)options; | ||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
File renamed without changes.
File renamed without changes.
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.
Is there a need for FIRSegmentationInterop?
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.
Is there a reason not to? What is the alternative? I thought all products were moving to using interop.
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.
Interop is only needed for products that want to manage their interface to other Firebase dependencies separately from their library implementation. Will Segmentation have Firebase pod dependencies?
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.
Yes, Segmentation will need to depend on IID and FIS.