Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
603119d
Create Segmentation SDK structure for source and unit tests. (#3214)
dmandar Jul 16, 2019
cb465a1
Add core support with interop for Segmentation SDK. (#3430)
dmandar Jul 25, 2019
0cf663a
Working drop of Segmentation SDK along with test app and unit tests. …
dmandar Jan 21, 2020
33a0579
update segmetation dependency version
ChaoqunCHEN May 15, 2020
e6b434c
migrate FloC SDK to depend on FIS SDK directly
ChaoqunCHEN May 15, 2020
8e06a28
format floc
ChaoqunCHEN May 15, 2020
b6eaf23
merge conflict
diwu-arete Sep 14, 2020
fabd519
format
ChaoqunCHEN Sep 15, 2020
20f4eb3
Merge branch 'master' of github.com:firebase/firebase-ios-sdk into cc…
diwu-arete Sep 15, 2020
bd017c4
using customized FIRapp
ChaoqunCHEN Sep 25, 2020
aa530db
merge master
ChaoqunCHEN Sep 25, 2020
aa58060
Merge branch 'segmentation-master' into ccq-floc
ChaoqunCHEN Sep 25, 2020
f2e331b
remove test plist file
ChaoqunCHEN Sep 25, 2020
9a3b226
Merge branch 'master' into segmentation-master
ChaoqunCHEN Sep 25, 2020
a8ab414
Merge branch 'master' into ccq-floc
ChaoqunCHEN Sep 25, 2020
7bd81cf
Merge branch 'segmentation-master' into ccq-floc
ChaoqunCHEN Sep 25, 2020
701c7a1
refactor to capture weakself
ChaoqunCHEN Sep 29, 2020
855f2d4
format
ChaoqunCHEN Sep 29, 2020
564bff2
replace partial mock with class mock
ChaoqunCHEN Sep 29, 2020
dc215c7
minor refactoring
ChaoqunCHEN Sep 29, 2020
278132b
use subscript to manipulate dictionary instance
ChaoqunCHEN Sep 29, 2020
a824c21
fix import error
ChaoqunCHEN Sep 30, 2020
8c9f5e4
minor refoctoring, addressing comments
ChaoqunCHEN Oct 1, 2020
ad3aa80
address comments
ChaoqunCHEN Oct 1, 2020
ce13a34
fix configurations
ChaoqunCHEN Oct 1, 2020
516e964
Merge branch 'master' into ccq-floc
ChaoqunCHEN Oct 1, 2020
0a88ac5
format
ChaoqunCHEN Oct 1, 2020
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ FirebaseStorage/Tests/Integration/Credentials.h
FirebaseStorage/Tests/SwiftIntegration/Credentials.swift
FirebaseStorageSwift/Tests/Integration/Credentials.swift

# FirebaseSegmentation integration tests GoogleService-Info.plist
FirebaseSegmentation/Tests/Sample/GoogleService-Info.plist

Secrets.tar

# OS X
Expand Down
4 changes: 4 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def labelsForModifiedFiles()
labels.push("api: instanceid") if @has_instanceid_changes
labels.push("api: messaging") if @has_messaging_changes
labels.push("api: remoteconfig") if @has_remoteconfig_changes
labels.push("api: segmentation") if @has_segmentation_changes
labels.push("api: storage") if @has_storage_changes
labels.push("GoogleDataTransport") if @has_gdt_changes
labels.push("GoogleUtilities") if @has_googleutilities_changes
Expand Down Expand Up @@ -102,6 +103,8 @@ has_license_changes = didModify(["LICENSE"])
@has_messaging_api_changes = hasChangesIn("FirebaseMessaging/Sources/Public/")
@has_remoteconfig_changes = hasChangesIn("FirebaseRemoteConfig/")
@has_remoteconfig_api_changes = hasChangesIn("FirebaseRemoteConfig/Sources/Public/")
@has_segmentation_changes = hasChangesIn("FirebaseSegmentation/")
@has_segmentation_api_changes = hasChangesIn("FirebaseSegmentation/Source/Public/
@has_storage_changes = hasChangesIn("FirebaseStorage/")
@has_storage_api_changes = hasChangesIn("FirebaseStorage/Sources/Public/")

Expand All @@ -125,6 +128,7 @@ has_license_changes = didModify(["LICENSE"])
@has_instanceid_api_changes ||
@has_messaging_api_changes ||
@has_remoteconfig_api_changes ||
@has_segmentation_api_changes ||
@has_storage_api_changes ||
@has_gdt_api_changes

Expand Down
45 changes: 45 additions & 0 deletions FirebaseSegmentation.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Pod::Spec.new do |s|
s.name = 'FirebaseSegmentation'
s.version = '0.1.0'
s.summary = 'Firebase Segmentation SDK'
s.description = <<-DESC
Firebase Segmentation enables you to associate your custom application instance ID with Firebase for user segmentation.
DESC

s.homepage = 'https://firebase.google.com'
s.license = { :type => 'Apache', :file => 'LICENSE' }
s.authors = 'Google, Inc.'
s.source = {
:git => 'https://github.com/firebase/firebase-ios-sdk.git',
:tag => 'Segmentation-' + s.version.to_s
}

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/**/*.[mh]',
'FirebaseCore/Sources/Private/*.h',
]
s.public_header_files = 'FirebaseSegmentation/Sources/Public/*.h'

s.dependency 'FirebaseCore', '~> 6.7'
s.dependency 'FirebaseInstallations', '~> 1.7'

header_search_paths = {
'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"'
}

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
Empty file.
78 changes: 78 additions & 0 deletions FirebaseSegmentation/Sources/FIRSegmentation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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 "FirebaseSegmentation/Sources/Public/FIRSegmentation.h"

#import "FirebaseCore/Sources/Private/FIRComponentContainer.h"
#import "FirebaseCore/Sources/Private/FIRLogger.h"
#import "FirebaseCore/Sources/Private/FIROptionsInternal.h"
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
#import "FirebaseSegmentation/Sources/Private/FIRSegmentationComponent.h"
#import "FirebaseSegmentation/Sources/SEGContentManager.h"

@implementation FIRSegmentation {
NSString *_firebaseAppName;
SEGContentManager *_contentManager;
}

+ (nonnull FIRSegmentation *)segmentation {
if (![FIRApp isDefaultAppConfigured]) {
[NSException
raise:kFirebaseSegmentationErrorDomain
format:@"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 FIRSegmentation 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 {
[_contentManager
associateCustomInstallationIdentiferNamed:customInstallationID
firebaseApp:_firebaseAppName
completion:^(BOOL success, NSDictionary *result) {
if (!success) {
// TODO(dmandar) log; pass along internal error code.
NSError *error = [NSError
errorWithDomain:kFirebaseSegmentationErrorDomain
code:FIRSegmentationErrorCodeInternal
userInfo:result];
completionHandler(error);
} else {
completionHandler(nil);
}
}];
}

/// Designated initializer
- (instancetype)initWithAppName:(NSString *)appName FIROptions:(FIROptions *)options {
self = [super init];
if (self) {
_firebaseAppName = appName;

// Initialize the content manager.
_contentManager = [SEGContentManager sharedInstanceWithOptions:options];
}
return self;
}

@end
107 changes: 107 additions & 0 deletions FirebaseSegmentation/Sources/FIRSegmentationComponent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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 "FirebaseSegmentation/Sources/Private/FIRSegmentationComponent.h"

#import "FirebaseCore/Sources/Private/FIRAppInternal.h"
#import "FirebaseCore/Sources/Private/FIRComponentContainer.h"
#import "FirebaseCore/Sources/Private/FIROptionsInternal.h"
#import "FirebaseSegmentation/Sources/Private/FIRSegmentationInternal.h"
#import "FirebaseSegmentation/Sources/SEGSegmentationConstants.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

@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;
if (!_segmentationInstance) {
_segmentationInstance = [[FIRSegmentation alloc] initWithAppName:app.name
FIROptions:app.options];
}
}
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
/// 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
Loading