Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDynamicLinks.podspec
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDynamicLinks.podspec --use-libraries
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseDynamicLinks.podspec --use-modular-headers

env:
- PROJECT=Segmentation PLATFORM=all METHOD=pod-lib-lint
before_install:
Expand Down
11 changes: 5 additions & 6 deletions FirebaseSegmentation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ Firebase Segmentation enables you to associate your custom application instance
}

s.ios.deployment_target = '8.0'

s.cocoapods_version = '>= 1.4.0'
s.static_framework = true
s.prefix_header_file = false

s.source_files = 'FirebaseSegmentation/Sources/**/*'
s.public_header_files = 'FirebaseSegmentation/Public/*.h'
s.public_header_files = 'FirebaseSegmentation/Sources/Public/*.h'

s.dependency 'FirebaseCore', '~> 6.0'
s.dependency 'FirebaseCore', '~> 6.1'
s.dependency 'FirebaseInstanceID', '~> 4.2'

header_search_paths = {
Expand All @@ -35,11 +34,11 @@ s.user_target_xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '$(PLATFORM_DIR)/Develope
s.pod_target_xcconfig = {
'GCC_C_LANGUAGE_STANDARD' => 'c99',
'GCC_PREPROCESSOR_DEFINITIONS' => 'FIRSegmentation_VERSION=' + s.version.to_s
}
}.merge(header_search_paths)

s.test_spec 'unit' do |unit_tests|
unit_tests.source_files = 'FirebaseSegmentation/Tests/Unit/*.[mh]'
unit_tests.dependency 'OCMock'
unit_tests.requires_app_host = true
end

end
end
45 changes: 44 additions & 1 deletion FirebaseSegmentation/Sources/FIRSegmentation.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,47 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#import "FIRSegmentation.h"
#import "FirebaseSegmentation/Sources/Public/FIRSegmentation.h"

#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRComponentContainer.h>
#import <FirebaseCore/FIRLogger.h>
#import <FirebaseCore/FIROptionsInternal.h>
#import <FirebaseSegmentation/Sources/Private/FIRSegmentationComponent.h>

FIRLoggerService kFIRLoggerSegmentation = @"[Firebase/Segmentation]";

@implementation FIRSegmentation {
NSString *_appName;
}

+ (nonnull FIRSegmentation *)segmentation {
if (![FIRApp isDefaultAppConfigured]) {
FIRLogError(kFIRLoggerSegmentation, @"I-SEG000001",
@"FIRApp not configured. Please make sure you have called [FIRApp configure]");
}

return [FIRSegmentation segmentationWithApp:[FIRApp defaultApp]];
}

+ (nonnull FIRSegmentation *)segmentationWithApp:(nonnull FIRApp *)firebaseApp {
// Use the provider to generate and return instances of FIRRemoteConfig for this specific app and
// namespace. This will ensure the app is configured before Remote Config can return an instance.
id<FIRSegmentationProvider> provider =
FIR_COMPONENT(FIRSegmentationProvider, firebaseApp.container);
return [provider segmentation];
}

- (void)setCustomInstallationID:(NSString *)customInstallationID
completion:(void (^)(NSError *))completionHandler {
}

/// Designated initializer
- (instancetype)initWithAppName:(NSString *)appName FIROptions:(FIROptions *)options {
self = [super init];
if (self) {
_appName = appName;
}
return self;
}
@end
105 changes: 105 additions & 0 deletions FirebaseSegmentation/Sources/FIRSegmentationComponent.m
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 FirebaseSegmentation/Sources/Private/FIRSegmentationComponent.h
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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

/// 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 FirebaseSegmentation/Sources/Private/FIRSegmentationInternal.h
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
16 changes: 6 additions & 10 deletions FirebaseSegmentation/Tests/Unit/SEGInitializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#import <XCTest/XCTest.h>

#import "FIRApp.h"
#import "FirebaseSegmentation/Sources/Public/FIRSegmentation.h"

@interface SEGInitializationTests : XCTestCase

@end
Expand All @@ -23,6 +26,7 @@ @implementation SEGInitializationTests
- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the
// class.
[FIRApp configure];
}

- (void)tearDown {
Expand All @@ -31,16 +35,8 @@ - (void)tearDown {
}

- (void)testExample {
NSLog(@"this is a test example");
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
FIRSegmentation *segmentation = [FIRSegmentation segmentation];
XCTAssertNotNil(segmentation);
}

@end