diff --git a/FirebaseSegmentation.podspec b/FirebaseSegmentation.podspec index 88fdf84c39..116ad59f51 100644 --- a/FirebaseSegmentation.podspec +++ b/FirebaseSegmentation.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FirebaseSegmentation' - s.version = '0.1.0' + s.version = '7.1.0-beta' s.summary = 'Firebase Segmentation SDK' s.description = <<-DESC Firebase Segmentation enables you to associate your custom application instance ID with Firebase for user segmentation. @@ -14,7 +14,7 @@ Firebase Segmentation enables you to associate your custom application instance :tag => 'Segmentation-' + s.version.to_s } - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '10.0' s.cocoapods_version = '>= 1.4.0' s.static_framework = true s.prefix_header_file = false @@ -25,16 +25,15 @@ Firebase Segmentation enables you to associate your custom application instance ] s.public_header_files = 'FirebaseSegmentation/Sources/Public/*.h' - s.dependency 'FirebaseCore', '~> 6.7' - s.dependency 'FirebaseInstallations', '~> 1.7' + s.dependency 'FirebaseCore', '~> 7.0' + s.dependency 'FirebaseInstallations', '~> 7.0' 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 + 'GCC_C_LANGUAGE_STANDARD' => 'c99' }.merge(header_search_paths) s.test_spec 'unit' do |unit_tests| diff --git a/FirebaseSegmentation/Sources/FIRSegmentationComponent.m b/FirebaseSegmentation/Sources/FIRSegmentationComponent.m index a2784b2bed..7d11f989eb 100644 --- a/FirebaseSegmentation/Sources/FIRSegmentationComponent.m +++ b/FirebaseSegmentation/Sources/FIRSegmentationComponent.m @@ -16,20 +16,10 @@ #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 "FirebaseCore/Sources/Private/FirebaseCoreInternal.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. @@ -82,9 +72,7 @@ add -DFIRSegmentation_VERSION=... to the build invocation" + (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)]]; + [FIRApp registerInternalLibrary:self withName:@"fire-seg"]; } #pragma mark - Interoperability diff --git a/FirebaseSegmentation/Sources/SEGContentManager.m b/FirebaseSegmentation/Sources/SEGContentManager.m index 3cdb48ec01..74811cf3db 100644 --- a/FirebaseSegmentation/Sources/SEGContentManager.m +++ b/FirebaseSegmentation/Sources/SEGContentManager.m @@ -67,24 +67,24 @@ // Get the latest installation identifier FIRInstallations *installation = [self installationForApp:firebaseApp]; if (installation == nil) { - completionHandler(NO, @{kErrorDescription : @"Firebase Installations SDK not available"}); + completionHandler(NO, @{kSEGErrorDescription : @"Firebase Installations SDK not available"}); } __weak SEGContentManager *weakSelf = self; - [installation - installationIDWithCompletion:^(NSString *_Nullable identifier, NSError *_Nullable error) { - SEGContentManager *strongSelf = weakSelf; - if (!strongSelf) { - completionHandler(NO, @{kErrorDescription : @"Internal Error getting installation ID."}); - return; - } + [installation installationIDWithCompletion:^(NSString *_Nullable identifier, + NSError *_Nullable error) { + SEGContentManager *strongSelf = weakSelf; + if (!strongSelf) { + completionHandler(NO, @{kSEGErrorDescription : @"Internal Error getting installation ID."}); + return; + } - [strongSelf associateInstallationWithLatestIdentifier:identifier - installation:installation - customizedIdentifier:customInstallationID - firebaseApp:firebaseApp - error:error - completion:completionHandler]; - }]; + [strongSelf associateInstallationWithLatestIdentifier:identifier + installation:installation + customizedIdentifier:customInstallationID + firebaseApp:firebaseApp + error:error + completion:completionHandler]; + }]; } - (void)associateInstallationWithLatestIdentifier:(NSString *_Nullable)identifier @@ -98,7 +98,7 @@ if (error) { errorMessage = [errorMessage stringByAppendingString:error.description]; } - NSDictionary *errorDictionary = @{kErrorDescription : errorMessage}; + NSDictionary *errorDictionary = @{kSEGErrorDescription : errorMessage}; completionHandler(NO, errorDictionary); return; } @@ -125,7 +125,7 @@ if (error) { errorMessage = [errorMessage stringByAppendingString:error.description]; } - NSDictionary *errorDictionary = @{kErrorDescription : errorMessage}; + NSDictionary *errorDictionary = @{kSEGErrorDescription : errorMessage}; completionHandler(NO, errorDictionary); return; } diff --git a/FirebaseSegmentation/Sources/SEGDatabaseManager.m b/FirebaseSegmentation/Sources/SEGDatabaseManager.m index dea90c087c..f34a992085 100644 --- a/FirebaseSegmentation/Sources/SEGDatabaseManager.m +++ b/FirebaseSegmentation/Sources/SEGDatabaseManager.m @@ -137,9 +137,9 @@ static BOOL SEGCreateFilePathIfNotExist(NSString *filePath) { FIRLogError(kFIRLoggerSegmentation, @"I-SEG00006", @"Failed to create table."); // Create a new database if existing database file is corrupted. if (!SEGCreateFilePathIfNotExist(dbPath)) { - completionHandler( - NO, - @{kSEGErrorDescription : @"Could not recreate database file at path: %@", dbpath}); + NSString *description = + [NSString stringWithFormat:@"Could not recreate database file at path: %@", dbPath]; + completionHandler(NO, @{kSEGErrorDescription : description}); return; } // Try to open the database with the new file. @@ -361,7 +361,7 @@ static BOOL SEGCreateFilePathIfNotExist(NSString *filePath) { int index = 1; for (NSString *param in array) { if (![self bindStringToStatement:statement index:index string:param]) { - return [self logErrorWithSQL:sql finalizeStatement:statement returnValue:NO]; + return [self logErrorWithSQL:nil finalizeStatement:statement returnValue:NO]; } index++; } diff --git a/FirebaseSegmentation/Sources/SEGSegmentationConstants.h b/FirebaseSegmentation/Sources/SEGSegmentationConstants.h index 5bfff99773..5e6efdc04c 100644 --- a/FirebaseSegmentation/Sources/SEGSegmentationConstants.h +++ b/FirebaseSegmentation/Sources/SEGSegmentationConstants.h @@ -27,25 +27,22 @@ } while (0); #endif -static NSString* const kFIRLoggerSegmentation = @"[Firebase/Segmentation]"; +extern NSString* const kFIRLoggerSegmentation; /// Keys for values stored in the Segmentation SDK. -static NSString* const kSEGFirebaseApplicationIdentifierKey = @"firebase_app_identifier"; -static NSString* const kSEGCustomInstallationIdentifierKey = @"custom_installation_identifier"; -static NSString* const kSEGFirebaseInstallationIdentifierKey = @"firebase_installation_identifier"; -static NSString* const kSEGAssociationStatusKey = @"association_status"; +extern NSString* const kSEGFirebaseApplicationIdentifierKey; +extern NSString* const kSEGCustomInstallationIdentifierKey; +extern NSString* const kSEGFirebaseInstallationIdentifierKey; +extern NSString* const kSEGAssociationStatusKey; /// Association Status -static NSString* const kSEGAssociationStatusPending = @"PENDING"; -static NSString* const kSEGAssociationStatusAssociated = @"ASSOCIATED"; +extern NSString* const kSEGAssociationStatusPending; +extern NSString* const kSEGAssociationStatusAssociated; /// Segmentation error domain when logging errors. -kFirebaseSegmentationErrorDomain = @"com.firebase.segmentation"; - -/// Segmentation FIRLogger domain. -static NSString* const kFIRLoggerSegmentation = @"[Firebase/Segmentation]"; +extern NSString* const kFirebaseSegmentationErrorDomain; /// Used for reporting generic internal Segmentation errors. -NSString* const kSEGErrorDescription = @"SEGErrorDescription"; +extern NSString* const kSEGErrorDescription; /// Segmentation Request Completion callback. /// @param success Decide whether the network operation succeeds. diff --git a/FirebaseSegmentation/Sources/SEGSegmentationConstants.m b/FirebaseSegmentation/Sources/SEGSegmentationConstants.m new file mode 100644 index 0000000000..60221c25bc --- /dev/null +++ b/FirebaseSegmentation/Sources/SEGSegmentationConstants.m @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Google LLC + * + * 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/SEGSegmentationConstants.h" + +NSString* const kFIRLoggerSegmentation = @"[Firebase/Segmentation]"; + +/// Keys for values stored in the Segmentation SDK. +NSString* const kSEGFirebaseApplicationIdentifierKey = @"firebase_app_identifier"; +NSString* const kSEGCustomInstallationIdentifierKey = @"custom_installation_identifier"; +NSString* const kSEGFirebaseInstallationIdentifierKey = @"firebase_installation_identifier"; +NSString* const kSEGAssociationStatusKey = @"association_status"; +/// Association Status +NSString* const kSEGAssociationStatusPending = @"PENDING"; +NSString* const kSEGAssociationStatusAssociated = @"ASSOCIATED"; + +/// Segmentation error domain when logging errors. +NSString* const kFirebaseSegmentationErrorDomain = @"com.firebase.segmentation"; + +/// Used for reporting generic internal Segmentation errors. +NSString* const kSEGErrorDescription = @"SEGErrorDescription"; + +/// Segmentation Request Completion callback. +/// @param success Decide whether the network operation succeeds. +/// @param result Return operation result data. +typedef void (^SEGRequestCompletion)(BOOL success, NSDictionary* result); diff --git a/FirebaseSegmentation/Tests/Unit/SEGContentManagerTests.m b/FirebaseSegmentation/Tests/Unit/SEGContentManagerTests.m index bf2e0fe676..2e150313db 100644 --- a/FirebaseSegmentation/Tests/Unit/SEGContentManagerTests.m +++ b/FirebaseSegmentation/Tests/Unit/SEGContentManagerTests.m @@ -71,9 +71,6 @@ authTokenWithCompletion:([OCMArg invokeBlockWithArgs:FISToken, [NSNull null], nil])]); // Mock the network manager. - FIROptions *options = [[FIROptions alloc] init]; - options.projectID = @"test-project-id"; - options.APIKey = @"AIzaSy-ApiKeyWithValidFormat_0123456789"; self.networkManagerMock = OCMClassMock([SEGNetworkManager class]); OCMStub([self.networkManagerMock makeAssociationRequestToBackendWithData:[OCMArg any] diff --git a/FirebaseSegmentation/Tests/Unit/SEGInitializationTests.m b/FirebaseSegmentation/Tests/Unit/SEGInitializationTests.m index d1d0220f6f..9c5b56105f 100644 --- a/FirebaseSegmentation/Tests/Unit/SEGInitializationTests.m +++ b/FirebaseSegmentation/Tests/Unit/SEGInitializationTests.m @@ -14,8 +14,7 @@ #import -#import "FirebaseCore/Sources/Public/FirebaseCore/FIRApp.h" -#import "FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h" +#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h" #import "FirebaseSegmentation/Sources/Public/FIRSegmentation.h" @interface FIRSegmentation (ForTest) @@ -31,7 +30,10 @@ @implementation SEGInitializationTests - (void)setUp { - FIROptions *options = [[FIROptions alloc] init]; + FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:@{ + @"API_KEY" : @"AIzaSy-ApiKeyWithValidFormat_0123456789", + @"PROJECT_ID" : @"test-firebase-project-id", + }]; options.APIKey = @"AIzaSy-ApiKeyWithValidFormat_0123456789"; options.projectID = @"test-firebase-project-id"; _segmentation = [[FIRSegmentation alloc] initWithAppName:@"test-firebase-app-name"