diff --git a/UnitTests/MPAppNotificationHandlerTests.m b/UnitTests/MPAppNotificationHandlerTests.m index e38707cf5..28c159832 100644 --- a/UnitTests/MPAppNotificationHandlerTests.m +++ b/UnitTests/MPAppNotificationHandlerTests.m @@ -11,7 +11,7 @@ @interface MParticle () + (dispatch_queue_t)messageQueue; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, readonly) MPAppNotificationHandler *appNotificationHandler; -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @end diff --git a/UnitTests/MPBackendControllerTests.m b/UnitTests/MPBackendControllerTests.m index 1af2ad774..6198627f1 100644 --- a/UnitTests/MPBackendControllerTests.m +++ b/UnitTests/MPBackendControllerTests.m @@ -17,7 +17,6 @@ #import "MPKitConfiguration.h" #import "MParticleSwift.h" #import "MPBaseTestCase.h" -#import "MPIUserDefaults.h" #import "MPDevice.h" #if TARGET_OS_IOS == 1 @@ -48,7 +47,7 @@ @interface MParticle (Tests) + (dispatch_queue_t)messageQueue; @property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; @property (nonatomic, strong, nullable) NSString *dataPlanId; @@ -114,8 +113,8 @@ - (void)setUp { [super setUp]; messageQueue = [MParticle messageQueue]; - [MPPersistenceController setMpid:@1]; - [MParticle sharedInstance].persistenceController = [[MPPersistenceController alloc] init]; + [MPPersistenceController_PRIVATE setMpid:@1]; + [MParticle sharedInstance].persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; [MParticle sharedInstance].stateMachine.apiKey = @"unit_test_app_key"; [MParticle sharedInstance].stateMachine.secret = @"unit_test_secret"; @@ -202,7 +201,7 @@ - (void)testBeginSession { dispatch_sync(messageQueue, ^{ [self.backendController beginSession]; self.session = self.backendController.session; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSMutableArray *sessions = [persistence fetchSessions]; MPSession *session = [sessions lastObject]; @@ -210,7 +209,7 @@ - (void)testBeginSession { XCTAssertEqualObjects(session, self.session, @"Sessions are not equal."); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -225,7 +224,7 @@ - (void)testBeginSession { } - (void)testEndSession { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; XCTestExpectation *expectation = [self expectationWithDescription:@"End session test"]; dispatch_sync(messageQueue, ^{ @@ -237,7 +236,7 @@ - (void)testEndSession { XCTAssertEqualObjects(session, stateMachine.currentSession, @"Current session and last session in the database are not equal."); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -260,7 +259,7 @@ - (void)testEndSession { [self.backendController endSession]; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -285,7 +284,7 @@ - (void)testEndSession { } - (void)testAutomaticSessionEnd { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; MParticle *mParticle = [MParticle sharedInstance]; id mockBackendController = OCMPartialMock(self.backendController); mParticle.backendController = mockBackendController; @@ -300,7 +299,7 @@ - (void)testAutomaticSessionEnd { XCTAssertEqualObjects(session, stateMachine.currentSession, @"Current session and last session in the database are not equal."); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -324,7 +323,7 @@ - (void)testAutomaticSessionEnd { } - (void)testBackgroundBlock { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; XCTestExpectation *expectation = [self expectationWithDescription:@"Begin background block test"]; dispatch_sync(messageQueue, ^{ @@ -336,7 +335,7 @@ - (void)testBackgroundBlock { XCTAssertEqualObjects(session, stateMachine.currentSession, @"Current session and last session in the database are not equal."); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -499,13 +498,13 @@ - (void)testBatchCycle { MPEvent *event = [[MPEvent alloc] initWithName:@"Unit Test Event" type:MPEventTypeOther]; event.customAttributes = @{@"key":@"value"}; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [self.backendController logEvent:event completionHandler:^(MPEvent *event, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"test"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:1]]; @@ -521,16 +520,16 @@ - (void)testBatchCycle { XCTAssertTrue(eventFound, @"Message for logEvent is not being saved."); - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] sessionId:[NSNumber numberWithLong:self->_session.sessionId] messages:messages sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:self->_session.sessionId] messages:messages sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder, @"Upload builder should not have been nil."); - [uploadBuilder withUserAttributes:[self.backendController userAttributesForUserId:[MPPersistenceController mpId]] deletedUserAttributes:nil]; - [uploadBuilder withUserIdentities:[self.backendController userIdentitiesForUserId:[MPPersistenceController mpId]]]; + [uploadBuilder withUserAttributes:[self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]] deletedUserAttributes:nil]; + [uploadBuilder withUserIdentities:[self.backendController userIdentitiesForUserId:[MPPersistenceController_PRIVATE mpId]]]; [uploadBuilder build:^(MPUpload *upload) { [persistence saveUpload:upload]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"test"]; NSArray *messageArray = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:1]]; @@ -550,7 +549,7 @@ - (void)testBatchCycle { } - (void)testUploadWithDifferentUser { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; //Set up Identity to exist [userDefaults setMPObject:[NSDate date] forKey:kMPLastIdentifiedDate userId:@1]; @@ -567,13 +566,13 @@ - (void)testUploadWithDifferentUser { MPEvent *event = [[MPEvent alloc] initWithName:@"Unit Test Event" type:MPEventTypeOther]; event.customAttributes = @{@"key":@"value"}; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [self.backendController logEvent:event completionHandler:^(MPEvent *event, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"test"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:1]]; @@ -590,7 +589,7 @@ - (void)testUploadWithDifferentUser { } XCTAssertTrue(eventFound, @"Message for logEvent is not being saved."); - [MPPersistenceController setMpid:@8]; + [MPPersistenceController_PRIVATE setMpid:@8]; [userDefaults setMPObject:[NSDate date] forKey:kMPLastIdentifiedDate userId:@8]; MParticleUser *newUser = [[MParticleUser alloc] init]; newUser.userId = @8; @@ -599,7 +598,7 @@ - (void)testUploadWithDifferentUser { XCTAssertNil([MParticle sharedInstance].identity.currentUser.identities[@(MPIdentityIOSAdvertiserId)]); - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:mpid sessionId:[NSNumber numberWithLong:self->_session.sessionId] messages:messages sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:mpid sessionId:[NSNumber numberWithLong:self->_session.sessionId] messages:messages sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder, @"Upload builder should not have been nil."); [uploadBuilder withUserAttributes:[self.backendController userAttributesForUserId:mpid] deletedUserAttributes:nil]; @@ -619,13 +618,13 @@ - (void)testLoggingCommerceEvent { MPCommerceEvent *commerceEvent = [[MPCommerceEvent alloc] initWithAction:MPCommerceEventActionClick]; commerceEvent.customAttributes = @{@"key":@"value"}; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [self.backendController logBaseEvent:commerceEvent completionHandler:^(MPBaseEvent *event, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -649,13 +648,13 @@ - (void)testLoggingBaseEvent { MPBaseEvent *event = [[MPBaseEvent alloc] initWithEventType:MPEventTypeOther]; event.customAttributes = @{@"key":@"value"}; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [self.backendController logBaseEvent:event completionHandler:^(MPBaseEvent *event, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -673,31 +672,31 @@ - (void)testRampUpload { XCTestExpectation *expectation = [self expectationWithDescription:@"Ramp upload test"]; dispatch_async(messageQueue, ^{ - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session messageInfo:@{@"MessageKey1":@"MessageValue1"}]; MPMessage *message = [messageBuilder build]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveMessage:message]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"test"]; NSArray *persistedMessages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:1]]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] sessionId:[NSNumber numberWithLong:self->_session.sessionId] messages:persistedMessages sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:self->_session.sessionId] messages:persistedMessages sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder, @"Upload builder should not have been nil."); if (!uploadBuilder) { return; } - [uploadBuilder withUserAttributes:[self.backendController userAttributesForUserId:[MPPersistenceController mpId]] deletedUserAttributes:nil]; - [uploadBuilder withUserIdentities:[self.backendController userIdentitiesForUserId:[MPPersistenceController mpId]]]; + [uploadBuilder withUserAttributes:[self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]] deletedUserAttributes:nil]; + [uploadBuilder withUserIdentities:[self.backendController userIdentitiesForUserId:[MPPersistenceController_PRIVATE mpId]]]; [uploadBuilder build:^(MPUpload *upload) { [persistence saveUpload:upload]; @@ -740,7 +739,7 @@ - (void)testDidBecomeActiveWithAppLink { dispatch_sync([MParticle messageQueue], ^{ NSDictionary *messagesDictionary = [[MParticle sharedInstance].persistenceController fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -832,7 +831,7 @@ - (void)testDidBecomeActive { dispatch_sync([MParticle messageQueue], ^{ NSDictionary *messagesDictionary = [[MParticle sharedInstance].persistenceController fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -880,7 +879,7 @@ - (void)testPreviousForegroundTime { dispatch_sync([MParticle messageQueue], ^{ NSDictionary *messagesDictionary = [[MParticle sharedInstance].persistenceController fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -926,7 +925,7 @@ - (void)testIsLaunchCheck { dispatch_sync([MParticle messageQueue], ^{ NSDictionary *messagesDictionary = [[MParticle sharedInstance].persistenceController fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -954,7 +953,7 @@ - (void)testIsLaunchCheck { - (void)testSetStringAttribute { [self.backendController setUserAttribute:@"foo attribute 1" value:@"foo value 1" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; NSString *value = attributes[@"foo attribute 1"]; XCTAssertEqualObjects(value, @"foo value 1"); } @@ -962,14 +961,14 @@ - (void)testSetStringAttribute { - (void)testSetExistingStringAttribute { [self.backendController setUserAttribute:@"foo attribute 1" value:@"foo value 1" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; [self.backendController setUserAttribute:@"foo attribute 1" value:@"foo value 2" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; NSString *value = attributes[@"foo attribute 1"]; XCTAssertEqualObjects(value, @"foo value 2"); } - (void)testSetStringArrayAttribute { [self.backendController setUserAttribute:@"foo attribute 1" values:@[@"foo value 1", @"foo value 2"] timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; NSArray *array = attributes[@"foo attribute 1"]; NSArray *result = @[@"foo value 1", @"foo value 2"]; XCTAssertEqualObjects(array, result); @@ -977,7 +976,7 @@ - (void)testSetStringArrayAttribute { - (void)testSetNumberAttribute { [self.backendController setUserAttribute:@"foo attribute 2" value:@12.34 timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; NSNumber *value = attributes[@"foo attribute 2"]; XCTAssertEqualObjects(value, @12.34); } @@ -988,28 +987,28 @@ - (void)testSetTooLongAttribute { [longValue appendString:@"T"]; } [self.backendController setUserAttribute:@"foo attribute 2" value:longValue timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(attributes, @{}); } - (void)testSetInvalidDateAttribute { NSDate *date = [NSDate date]; [self.backendController setUserAttribute:@"foo attribute 2" value:date timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(attributes, @{}); } - (void)testSetInvalidNullAttribute { NSNull *nullObject = [NSNull null]; [self.backendController setUserAttribute:@"foo attribute 2" value:nullObject timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(attributes, @{}); } - (void)testIncrementInvalidAttribute { [self.backendController setUserAttribute:@"foo attribute 2" value:@"foo value 2" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; [self.backendController incrementUserAttribute:@"foo attribute 2" byValue:@1]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; NSString *value = attributes[@"foo attribute 2"]; XCTAssertEqualObjects(value, @"foo value 2"); } @@ -1017,14 +1016,14 @@ - (void)testIncrementInvalidAttribute { - (void)testRemoveNumberAttribute { [self.backendController setUserAttribute:@"foo attribute 2" value:@12.34 timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; [self.backendController removeUserAttribute:@"foo attribute 2" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, id _Nullable value, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(attributes, @{}); } - (void)testRemoveStringAttribute { [self.backendController setUserAttribute:@"foo attribute 2" value:@"foo value 2" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, NSArray * _Nullable values, MPExecStatus execStatus) {}]; [self.backendController removeUserAttribute:@"foo attribute 2" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, id _Nullable value, MPExecStatus execStatus) {}]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(attributes, @{}); } @@ -1036,7 +1035,7 @@ - (void)testSetUserTagFromBackendController { [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:DEFAULT_TIMEOUT handler:nil]; - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqual(attributes.count, 1); NSString *value = attributes[@"foo tag 1"]; XCTAssertEqualObjects(value, [NSNull null]); @@ -1047,7 +1046,7 @@ - (void)testSetUserTagFromUser { XCTestExpectation *expectation = [self expectationWithDescription:@"async work"]; dispatch_async([MParticle messageQueue], ^{ - NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *attributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqual(attributes.count, 1); NSString *value = attributes[@"foo tag 1"]; XCTAssertEqualObjects(value, [NSNull null]); @@ -1088,12 +1087,12 @@ - (void)testSetUserAttributeKits { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; } [self.backendController setUserAttribute:@"foo attribute 3" value:@"foo value 3" timestamp:[NSDate date] completionHandler:^(NSString * _Nonnull key, id _Nullable value, MPExecStatus execStatus) {}]; - NSDictionary *userAttributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *userAttributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(userAttributes, @{@"foo attribute 3":@"foo value 3"}); } @@ -1102,16 +1101,16 @@ - (void)testUserAttributeChanged { [self.backendController beginSession]; }); self.session = self.backendController.session; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveSession:self.backendController.session]; [self.backendController setUserAttribute:@"TardisModel" value:@"Police Call Box" timestamp:[NSDate date] completionHandler:nil]; - NSDictionary *userAttributes = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]]; + NSDictionary *userAttributes = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertEqualObjects(userAttributes[@"TardisModel"], @"Police Call Box"); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1131,7 +1130,7 @@ - (void)testUserAttributeChanged { [persistence deleteSession:self.backendController.session]; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1141,7 +1140,7 @@ - (void)testUserAttributeChanged { [self.backendController removeUserAttribute:@"TardisModel" timestamp:[NSDate date] completionHandler:nil]; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1160,11 +1159,11 @@ - (void)testUserAttributeChangedFromIncrement { [self.backendController beginSession]; }); self.session = self.backendController.session; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveSession:self.backendController.session]; NSString *userAttributeKey = @"Number of time travels"; - NSNumber *userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]][userAttributeKey]; + NSNumber *userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]][userAttributeKey]; XCTAssertNil(userAttributeValue); userAttributeValue = [self.backendController incrementUserAttribute:userAttributeKey byValue:@1]; @@ -1172,7 +1171,7 @@ - (void)testUserAttributeChangedFromIncrement { XCTAssertEqualObjects(userAttributeValue, @1); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1193,7 +1192,7 @@ - (void)testUserAttributeChangedFromIncrement { [persistence deleteSession:self.backendController.session]; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1205,7 +1204,7 @@ - (void)testUserAttributeChangedFromIncrement { XCTAssertEqualObjects(userAttributeValue, @3); messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1226,20 +1225,20 @@ - (void)testUserIdentityChanged { self.session = self.backendController.session; XCTestExpectation *expectation = [self expectationWithDescription:@"User identity changed"]; __weak MPBackendControllerTests *weakSelf = self; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveSession:weakSelf.session]; [weakSelf.backendController setUserIdentity:@"The Most Interesting Man in the World" identityType:MPUserIdentityCustomerId timestamp:[NSDate date] completionHandler:^(NSString * _Nullable identityString, MPUserIdentity identityType, MPExecStatus execStatus) { }]; __block NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF[%@] == %@", @"n", @(MPUserIdentityCustomerId)]; - __block NSDictionary *userIdentity = [[[self.backendController userIdentitiesForUserId:[MPPersistenceController mpId]] filteredArrayUsingPredicate:predicate] lastObject]; + __block NSDictionary *userIdentity = [[[self.backendController userIdentitiesForUserId:[MPPersistenceController_PRIVATE mpId]] filteredArrayUsingPredicate:predicate] lastObject]; XCTAssertNotNil(userIdentity); XCTAssertEqualObjects(userIdentity[@"i"], @"The Most Interesting Man in the World"); XCTAssertEqualObjects(userIdentity[@"n"], @(MPUserIdentityCustomerId)); __block NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - __block NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + __block NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; __block NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; __block NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; __block NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1265,7 +1264,7 @@ - (void)testUserIdentityChanged { self.session = self.backendController.session; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1274,11 +1273,11 @@ - (void)testUserIdentityChanged { }); [weakSelf.backendController setUserIdentity:nil identityType:MPUserIdentityCustomerId timestamp:[NSDate date] completionHandler:^(NSString * _Nullable identityString, MPUserIdentity identityType, MPExecStatus execStatus) { - userIdentity = [[[weakSelf.backendController userIdentitiesForUserId:[MPPersistenceController mpId]] filteredArrayUsingPredicate:predicate] lastObject]; + userIdentity = [[[weakSelf.backendController userIdentitiesForUserId:[MPPersistenceController_PRIVATE mpId]] filteredArrayUsingPredicate:predicate] lastObject]; XCTAssertNil(userIdentity); messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1305,19 +1304,19 @@ - (void)testIncrementUserAttribute { XCTestExpectation *expectation = [self expectationWithDescription:@"Increment user attribute"]; dispatch_sync(messageQueue, ^{ NSString *userAttributeKey = @"Number of time travels"; - NSNumber *userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]][userAttributeKey]; + NSNumber *userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]][userAttributeKey]; XCTAssertNil(userAttributeValue); userAttributeValue = [self.backendController incrementUserAttribute:userAttributeKey byValue:@1]; XCTAssertNotNil(userAttributeValue); XCTAssertEqualObjects(userAttributeValue, @1); - userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]][userAttributeKey]; + userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]][userAttributeKey]; XCTAssertNotNil(userAttributeValue); XCTAssertEqualObjects(userAttributeValue, @1); [self.backendController removeUserAttribute:userAttributeKey timestamp:[NSDate date] completionHandler:nil]; - userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController mpId]][userAttributeKey]; + userAttributeValue = [self.backendController userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]][userAttributeKey]; XCTAssertNil(userAttributeValue); [expectation fulfill]; }); @@ -1335,13 +1334,13 @@ - (void)testSetLocation { XCTestExpectation *expectation = [self expectationWithDescription:@"Set location"]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [self.backendController logEvent:event completionHandler:^(MPEvent *event, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:self->_session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1376,12 +1375,12 @@ - (void)testSessionAttributesAndIncrement { } - (void)testMessageWithOptOut { - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [MParticle sharedInstance].stateMachine.optOut = YES; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -1390,19 +1389,19 @@ - (void)testMessageWithOptOut { [[MParticle sharedInstance].backendController saveMessage:message updateSession:NO]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSArray *messages = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; XCTAssertEqual(messages.count, 0, @"No Messages should be saved."); } - (void)testMessageWithOptOutMessage { - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [MParticle sharedInstance].stateMachine.optOut = YES; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeOptOut session:session messageInfo:@{kMPOptOutStatus:(@"true")}]; @@ -1412,14 +1411,14 @@ - (void)testMessageWithOptOutMessage { XCTAssertTrue(message.messageId > 0, @"Message id not greater than zero: %lld", message.messageId); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSArray *messages = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; XCTAssertEqual(messages.count, 1, @"The Opt Out Message wasn't saved."); } - (void)testBatchAndMessageLimitsMessagesPerBatch { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSMutableArray *unlimitedMessages = [NSMutableArray array]; for (int i=0; i<10; i++) { @@ -1439,7 +1438,7 @@ - (void)testBatchAndMessageLimitsMessagesPerBatch { } - (void)testBatchAndMessageLimitsMultipleMessagesPerBatch { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSMutableArray *unlimitedMessages = [NSMutableArray array]; for (int i=0; i<10; i++) { @@ -1459,7 +1458,7 @@ - (void)testBatchAndMessageLimitsMultipleMessagesPerBatch { } - (void)testBatchAndMessageLimitsBytesPerBatch { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session messageInfo:@{@"MessageKey1":@"MessageValue1"}]; @@ -1484,7 +1483,7 @@ - (void)testBatchAndMessageLimitsBytesPerBatch { } - (void)testBatchAndMessageLimitsBytesPerMessage { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSString *longString = @"a"; while (longString.length < 1000) { longString = [NSString stringWithFormat:@"%@%@", longString, longString]; @@ -1515,7 +1514,7 @@ - (void)testBatchAndMessageLimitsBytesPerMessage { } - (MPMessage *)messageWithType:(MPMessageType)type andLength:(NSInteger)length { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSString *longString = @"a"; while (longString.length < length) { longString = [NSString stringWithFormat:@"%@%@", longString, longString]; @@ -1669,7 +1668,7 @@ - (void)testHandleDeviceTokenNotification { XCTAssert([value isKindOfClass:[MPMessage class]]); MPMessage *returnedMessage = ((MPMessage *)value); NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:returnedMessage.messageData options:0 error:nil]; - XCTAssertEqualObjects(dic[@"to"], [MPIUserDefaults stringFromDeviceToken:testDeviceToken]); + XCTAssertEqualObjects(dic[@"to"], [MPUserDefaults stringFromDeviceToken:testDeviceToken]); return YES; }] updateSession:YES]; @@ -1700,9 +1699,9 @@ - (void)testLogCrash { plCrashReport:plCrashReport completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1741,9 +1740,9 @@ - (void)testLogCrashNilMessage { plCrashReport:plCrashReport completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1782,9 +1781,9 @@ - (void)testLogCrashNilStackTrace { plCrashReport:plCrashReport completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1813,7 +1812,7 @@ - (void)testLogCrashNilPlCrashReport { }); self.session = self.backendController.session; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSString *message = @"crash report"; NSString *stackTrace = @"stack track from crash report"; @@ -1824,7 +1823,7 @@ - (void)testLogCrashNilPlCrashReport { completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1853,12 +1852,12 @@ - (void)testLogCrashTruncatePlCrashReport { }); self.session = self.backendController.session; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSString *message = @"crash report"; NSString *stackTrace = @"stack track from crash report"; NSString *plCrashReport = @"a"; - while (plCrashReport.length < [MPPersistenceController maxBytesPerEvent:kMPMessageTypeStringCrashReport]) { + while (plCrashReport.length < [MPPersistenceController_PRIVATE maxBytesPerEvent:kMPMessageTypeStringCrashReport]) { plCrashReport = [NSString stringWithFormat:@"%@%@", plCrashReport, plCrashReport]; } @@ -1868,7 +1867,7 @@ - (void)testLogCrashTruncatePlCrashReport { completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1915,9 +1914,9 @@ - (void)testLogCrashTruncatePlCrashReportField { plCrashReport:plCrashReport completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -1966,9 +1965,9 @@ - (void)testLogCrashTruncatePlCrashReportFieldNil { plCrashReport:plCrashReport completionHandler:^(NSString * _Nullable message, MPExecStatus execStatus) {}]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:@0]; // no crash session to recover so sessionId = 0 NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -2002,7 +2001,7 @@ - (void)testUserIdentitiesForUserIdNoInvalidIdTypes { NSArray *userIdentities = @[validUserId]; MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:userIdentities forKey:kMPUserIdentityArrayKey userId:currentUser.userId]; NSArray *currentUserIdentities = [[[MParticle sharedInstance] backendController] userIdentitiesForUserId:currentUser.userId]; @@ -2026,7 +2025,7 @@ - (void)testUserIdentitiesForUserIdOneInvalidIdType { NSArray *userIdentities = @[validUserId, invalidUserId]; MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:userIdentities forKey:kMPUserIdentityArrayKey userId:currentUser.userId]; NSArray *currentUserIdentities = [[[MParticle sharedInstance] backendController] userIdentitiesForUserId:currentUser.userId]; @@ -2055,7 +2054,7 @@ - (void)testUserIdentitiesForUserIdMultipleInvalidIdTypes { NSArray *userIdentities = @[validUserId, invalidUserId, invalidUserId2]; MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:userIdentities forKey:kMPUserIdentityArrayKey userId:currentUser.userId]; NSArray *currentUserIdentities = [[[MParticle sharedInstance] backendController] userIdentitiesForUserId:currentUser.userId]; @@ -2072,7 +2071,7 @@ - (void)testPersistanceMaxAgeCleanup { instance.options = options; MPBackendController_PRIVATE *backendController = [[MPBackendController_PRIVATE alloc] init]; - MPPersistenceController *persistenceController = [[MPPersistenceController alloc] init]; + MPPersistenceController_PRIVATE *persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; id mockPersistenceController = OCMPartialMock(persistenceController); NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970]; diff --git a/UnitTests/MPBaseTestCase.m b/UnitTests/MPBaseTestCase.m index d58ea2f0b..a7d7a18be 100644 --- a/UnitTests/MPBaseTestCase.m +++ b/UnitTests/MPBaseTestCase.m @@ -13,7 +13,7 @@ #import "MPIConstants.h" @interface MParticle (Tests) -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @end @interface MPTestConnectorFactory : NSObject @@ -39,7 +39,7 @@ - (void)setUpWithCompletionHandler:(void (^)(NSError * _Nullable))completion { MParticle *instance = [MParticle sharedInstance]; if (!instance.persistenceController) { // Ensure we have a persistence controller to reset the db etc - instance.persistenceController = [[MPPersistenceController alloc] init]; + instance.persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; } [instance reset:^{ diff --git a/UnitTests/MPCustomModuleTests.m b/UnitTests/MPCustomModuleTests.m index b93fdaa2e..35ae69e50 100644 --- a/UnitTests/MPCustomModuleTests.m +++ b/UnitTests/MPCustomModuleTests.m @@ -92,7 +92,7 @@ - (NSDictionary *)customModuleConfiguration { - (void)setUp { [super setUp]; - [MPPersistenceController setMpid:@1]; + [MPPersistenceController_PRIVATE setMpid:@1]; } - (void)testConfiguration { diff --git a/UnitTests/MPDataModelTests.m b/UnitTests/MPDataModelTests.m index bcf01ea4e..21a028a95 100644 --- a/UnitTests/MPDataModelTests.m +++ b/UnitTests/MPDataModelTests.m @@ -8,6 +8,7 @@ #import "MPPersistenceController.h" #import "MPBaseTestCase.h" #import "mParticle.h" +#import "MParticleSwift.h" @interface MParticle () @@ -29,7 +30,7 @@ - (void)setUp { } - (void)testSessionInstance { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertNotNil(session, @"Should not have been nil"); MPSession *sessionCopy = [session copy]; @@ -63,7 +64,7 @@ - (void)testSessionInstance { } - (void)testMessageInstance { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -149,7 +150,7 @@ - (void)testFixInvalidKeysInDictionary { } - (void)testMessageInstanceWithInfinite { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; double four = 4.0; double zed = 0.0; @@ -185,7 +186,7 @@ - (void)testMessageInstanceWithInfinite { } - (void)testUploadInstance { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -199,7 +200,7 @@ - (void)testUploadInstance { kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(upload, @"Should not have been nil."); NSString *description = [upload description]; @@ -227,7 +228,7 @@ - (void)testUploadInstance { } - (void)testBreadcrumbInstance { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -275,7 +276,7 @@ - (void)testBreadcrumbInstance { } - (void)testMessageEncoding { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -290,7 +291,7 @@ - (void)testMessageEncoding { } - (void)testBreadcrumbEncoding { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session diff --git a/UnitTests/MPDeviceTests.m b/UnitTests/MPDeviceTests.m index aca44d3f7..8b6fe4db5 100644 --- a/UnitTests/MPDeviceTests.m +++ b/UnitTests/MPDeviceTests.m @@ -1,8 +1,16 @@ #import #import #import "MPDevice.h" -#import "MPIUserDefaults.h" +#import "mParticle.h" #import "MPIConstants.h" +#import "MParticleSwift.h" + +@interface MParticle () + +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; + +@end @interface MPDeviceTests : XCTestCase @@ -23,7 +31,7 @@ - (void)testTelephonyRadioAccessTechnology { - (void)testDictionaryDescription { #if TARGET_OS_IOS == 1 - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSData *testDeviceToken = [@"<000000000000000000000000000000>" dataUsingEncoding:NSUTF8StringEncoding]; userDefaults[kMPDeviceTokenKey] = testDeviceToken; diff --git a/UnitTests/MPEventTests.m b/UnitTests/MPEventTests.m index 8af4e084e..cad49fb14 100644 --- a/UnitTests/MPEventTests.m +++ b/UnitTests/MPEventTests.m @@ -145,7 +145,7 @@ - (void)testInvalidTypes { } - (void)testDictionaryRepresentation { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance].stateMachine; stateMachine.currentSession = session; @@ -179,7 +179,7 @@ - (void)testDictionaryRepresentation { } - (void)testDictionaryRepresentationWithDictionaryValues { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance].stateMachine; stateMachine.currentSession = session; @@ -214,7 +214,7 @@ - (void)testDictionaryRepresentationWithDictionaryValues { } - (void)testDictionaryRepresentationWithDictionaryValuesContainingDictionary { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance].stateMachine; stateMachine.currentSession = session; @@ -249,7 +249,7 @@ - (void)testDictionaryRepresentationWithDictionaryValuesContainingDictionary { } - (void)testDictionaryRepresentationWithNullValues { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance].stateMachine; stateMachine.currentSession = session; diff --git a/UnitTests/MPIdentityTests.m b/UnitTests/MPIdentityTests.m index 04c717680..cfb8497ba 100644 --- a/UnitTests/MPIdentityTests.m +++ b/UnitTests/MPIdentityTests.m @@ -13,7 +13,6 @@ #import "MPKitContainer.h" #import "MPPersistenceController.h" #import "MPStateMachine.h" -#import "MPIUserDefaults.h" typedef NS_ENUM(NSUInteger, MPIdentityRequestType) { MPIdentityRequestIdentify = 0, @@ -59,7 +58,7 @@ - (instancetype)initWithIdentities:(NSDictionary *)identities; @interface MParticle () @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @end @@ -610,7 +609,7 @@ - (void)testIdentityRequestComplete { } - (void)testIdentifyIdentityRequestCompleteWithKits { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"42"] mpId]; id mockInstance = OCMClassMock([MParticle class]); @@ -642,7 +641,7 @@ - (void)testIdentifyIdentityRequestCompleteWithKits { } - (void)testLoginIdentityRequestCompleteWithKits { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"42"] mpId]; id mockInstance = OCMClassMock([MParticle class]); @@ -674,7 +673,7 @@ - (void)testLoginIdentityRequestCompleteWithKits { } - (void)testLogoutIdentityRequestCompleteWithKits { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"42"] mpId]; id mockInstance = OCMClassMock([MParticle class]); @@ -702,7 +701,7 @@ - (void)testLogoutIdentityRequestCompleteWithKits { } - (void)testIdentifyIdentityRequestCompleteWithKitsAndNoUserChange { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"42"] mpId]; id mockInstance = OCMClassMock([MParticle class]); @@ -734,7 +733,7 @@ - (void)testIdentifyIdentityRequestCompleteWithKitsAndNoUserChange { } - (void)testLoginIdentityRequestCompleteWithKitsAndNoUserChange { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"42"] mpId]; id mockInstance = OCMClassMock([MParticle class]); @@ -766,7 +765,7 @@ - (void)testLoginIdentityRequestCompleteWithKitsAndNoUserChange { } - (void)testLogoutIdentityRequestCompleteWithKitsAndNoUserChange { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"42"] mpId]; id mockInstance = OCMClassMock([MParticle class]); @@ -794,7 +793,7 @@ - (void)testLogoutIdentityRequestCompleteWithKitsAndNoUserChange { } - (void)testMPIdZeroToMPId { - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[[mockPersistenceController stub] andReturn:@"0"] mpId]; id mockInstance = OCMClassMock([MParticle class]); diff --git a/UnitTests/MPKitAPITests.m b/UnitTests/MPKitAPITests.m index c383965a8..083cc357b 100644 --- a/UnitTests/MPKitAPITests.m +++ b/UnitTests/MPKitAPITests.m @@ -10,7 +10,6 @@ #import "MPPersistenceController.h" #import "MPKitContainer.h" #import "MPKitConfiguration.h" -#import "MPIUserDefaults.h" #import "MPIConstants.h" @interface MPKitContainer_PRIVATE () @@ -22,8 +21,9 @@ @interface MPKitContainer_PRIVATE () @interface MParticle () + (dispatch_queue_t)messageQueue; +@property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong) MPBackendController_PRIVATE *backendController; -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; @end @@ -58,7 +58,7 @@ - (void)setUp { [MParticle sharedInstance].kitContainer_PRIVATE = [[MPKitContainer_PRIVATE alloc] init]; _kitContainer = [MParticle sharedInstance].kitContainer_PRIVATE; - [MParticle sharedInstance].persistenceController = [[MPPersistenceController alloc] init]; + [MParticle sharedInstance].persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; NSSet> *registeredKits = [MPKitContainer_PRIVATE registeredKits]; if (!registeredKits) { @@ -119,7 +119,7 @@ - (void)testUserIdentities { @"f":@NO } ]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:userIdentities forKey:kMPUserIdentityArrayKey userId:currentUser.userId]; [userDefaults removeMPObjectForKey:@"ua"]; @@ -162,7 +162,7 @@ - (void)testUserAttributeFromCache { @"better data":@"ABC", @"bad data":@"12345" }; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:userAttributes forKey:kMPUserAttributeKey userId:currentUser.userId]; NSString *goodHashedKey = [MPIHasher hashString:@"good data"]; diff --git a/UnitTests/MPKitContainerTests.m b/UnitTests/MPKitContainerTests.m index 7ed668f75..d592b2cd3 100644 --- a/UnitTests/MPKitContainerTests.m +++ b/UnitTests/MPKitContainerTests.m @@ -21,7 +21,6 @@ #import "MPTransactionAttributes.h" #import "MPEventProjection.h" #import "MPKitConfiguration.h" -#import "MPIUserDefaults.h" #import "MPForwardQueueParameters.h" #import "MPConsentKitFilter.h" #import "MPPersistenceController.h" @@ -36,7 +35,7 @@ @interface MParticle () + (dispatch_queue_t)messageQueue; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; -@property (nonatomic, strong, readonly) MPBackendController_PRIVATE *backendController; +@property (nonatomic, strong) MPBackendController_PRIVATE *backendController; @end @@ -92,6 +91,8 @@ - (void)setUp { [MParticle sharedInstance].kitContainer_PRIVATE = [[MPKitContainer_PRIVATE alloc] init]; kitContainer = [MParticle sharedInstance].kitContainer_PRIVATE; + + [MParticle sharedInstance].backendController = [[MPBackendController_PRIVATE alloc] initWithDelegate:(id)[MParticle sharedInstance]]; NSSet> *registeredKits = [MPKitContainer_PRIVATE registeredKits]; if (!registeredKits) { @@ -133,7 +134,7 @@ - (void)tearDown { } - (void)setUserAttributesAndIdentities { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSDictionary *userAttributes = @{@"Dinosaur":@"T-Rex", @"Arm length":@"Short", @"Height":@20, @@ -190,11 +191,11 @@ - (void)testUpdateKitConfiguration { MPResponseConfig *responseConfig = [[MPResponseConfig alloc] initWithConfiguration:configuration stateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController]; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertEqualObjects(responseConfig.configuration, [MPIUserDefaults restore].configuration); + XCTAssertEqualObjects(responseConfig.configuration, [MPUserDefaults restore].configuration); - NSArray *directoryContents = [[MPIUserDefaults standardUserDefaults] getKitConfigurations]; + NSArray *directoryContents = [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getKitConfigurations]; for (NSDictionary *kitConfigurationDictionary in directoryContents) { MPKitConfiguration *kitConfiguration = [[MPKitConfiguration alloc] initWithDictionary:kitConfigurationDictionary]; if ([[kitConfiguration integrationId] isEqual:@(42)]){ @@ -241,14 +242,14 @@ - (void)testRemoveKitConfiguration { MPResponseConfig *responseConfig = [[MPResponseConfig alloc] initWithConfiguration:configuration stateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController]; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertEqualObjects(responseConfig.configuration, [MPIUserDefaults restore].configuration); + XCTAssertEqualObjects(responseConfig.configuration, [MPUserDefaults restore].configuration); dispatch_sync(dispatch_get_main_queue(), ^{ }); - XCTAssertEqual(@"cool app key", [self->kitContainer.kitConfigurations objectForKey:@(42)].configuration[@"appId"]); + XCTAssertEqualObjects(@"cool app key", [self->kitContainer.kitConfigurations objectForKey:@(42)].configuration[@"appId"]); - NSArray *directoryContents = [[MPIUserDefaults standardUserDefaults] getKitConfigurations]; + NSArray *directoryContents = [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getKitConfigurations]; for (NSDictionary *kitConfigurationDictionary in directoryContents) { MPKitConfiguration *kitConfiguration = [[MPKitConfiguration alloc] initWithDictionary:kitConfigurationDictionary]; if ([[kitConfiguration integrationId] isEqual:@(42)]){ @@ -273,13 +274,13 @@ - (void)testRemoveKitConfiguration { responseConfig = [[MPResponseConfig alloc] initWithConfiguration:configuration stateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController]; requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertEqualObjects(responseConfig.configuration, [MPIUserDefaults restore].configuration); + XCTAssertEqualObjects(responseConfig.configuration, [MPUserDefaults restore].configuration); XCTAssertEqual(@"cool app key", [self->kitContainer.kitConfigurations objectForKey:@(42)].configuration[@"appId"]); - directoryContents = [[MPIUserDefaults standardUserDefaults] getKitConfigurations]; + directoryContents = [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getKitConfigurations]; for (NSDictionary *kitConfigurationDictionary in directoryContents) { MPKitConfiguration *kitConfiguration = [[MPKitConfiguration alloc] initWithDictionary:kitConfigurationDictionary]; if ([[kitConfiguration integrationId] isEqual:@(42)]){ @@ -296,7 +297,7 @@ - (void)testRemoveKitConfiguration { } - (void)testIsDisabledByBracketConfiguration { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[@"mpid"] = @2; NSDictionary *bracketConfig = @{@"hi":@(0),@"lo":@(0)}; @@ -2239,7 +2240,7 @@ - (void)testIsDisabledByConsentKitFilterGPDR { [state setGDPRConsentState:[gdprState copy]]; - [MPPersistenceController setConsentState:state forMpid:[MPPersistenceController mpId]]; + [MPPersistenceController_PRIVATE setConsentState:state forMpid:[MPPersistenceController_PRIVATE mpId]]; MParticle.sharedInstance.identity.currentUser.consentState = state; isDisabled = [[MParticle sharedInstance].kitContainer_PRIVATE isDisabledByConsentKitFilter:filter]; @@ -2279,7 +2280,7 @@ - (void)testIsDisabledByConsentKitFilterCCPA { [state setCCPAConsentState: [ccpaConsent copy]]; - [MPPersistenceController setConsentState:state forMpid:[MPPersistenceController mpId]]; + [MPPersistenceController_PRIVATE setConsentState:state forMpid:[MPPersistenceController_PRIVATE mpId]]; MParticle.sharedInstance.identity.currentUser.consentState = state; BOOL isDisabled = [[MParticle sharedInstance].kitContainer_PRIVATE isDisabledByConsentKitFilter:filter]; @@ -2611,7 +2612,7 @@ - (void)testForwardEventToSideloadedKit { } - (void)testAppInfoContainsSideloadKitsFlag { - [[MPIUserDefaults standardUserDefaults] setSideloadedKitsCount:3]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setSideloadedKitsCount:3]; NSDictionary *dict = [[[MPApplication_PRIVATE alloc] init] dictionaryRepresentation]; diff --git a/UnitTests/MPMessageBuilderTests.m b/UnitTests/MPMessageBuilderTests.m index 6c7caf20a..13b784b4f 100644 --- a/UnitTests/MPMessageBuilderTests.m +++ b/UnitTests/MPMessageBuilderTests.m @@ -47,7 +47,7 @@ - (MPSession *)session { return _session; } - _session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + _session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; return _session; } @@ -371,13 +371,13 @@ - (void)testMessageUserIdNilSession { @"key2":@"value2", @"key3":@"value3"}; - [MPPersistenceController setMpid:@1]; + [MPPersistenceController_PRIVATE setMpid:@1]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:nil messageInfo:messageInfo]; MPMessage *message = [messageBuilder build]; - XCTAssertEqualObjects([MPPersistenceController mpId], message.userId); + XCTAssertEqualObjects([MPPersistenceController_PRIVATE mpId], message.userId); } - (void)testMessageUserIdSessionIdZero { @@ -385,14 +385,14 @@ - (void)testMessageUserIdSessionIdZero { @"key2":@"value2", @"key3":@"value3"}; - [MPPersistenceController setMpid:@1]; + [MPPersistenceController_PRIVATE setMpid:@1]; MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:@0]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session messageInfo:messageInfo]; MPMessage *message = [messageBuilder build]; - XCTAssertEqualObjects([MPPersistenceController mpId], message.userId); + XCTAssertEqualObjects([MPPersistenceController_PRIVATE mpId], message.userId); } @end diff --git a/UnitTests/MPNetworkCommunicationTests.m b/UnitTests/MPNetworkCommunicationTests.m index 531511218..5c4cfa5f3 100644 --- a/UnitTests/MPNetworkCommunicationTests.m +++ b/UnitTests/MPNetworkCommunicationTests.m @@ -6,7 +6,6 @@ #import "MPApplication.h" #import "MPUpload.h" #import "MPConnector.h" -#import "MPIUserDefaults.h" #import "MPBaseTestCase.h" #import "mParticle.h" #import "MPPersistenceController.h" @@ -19,7 +18,8 @@ @interface MParticle () @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readwrite) MPNetworkOptions *networkOptions; - (void)logKitBatch:(NSString *)batch; @@ -41,6 +41,15 @@ @interface MPNetworkCommunicationTests : MPBaseTestCase @implementation MPNetworkCommunicationTests +- (void)setUp { + [super setUp]; + + [MParticle sharedInstance].stateMachine.apiKey = @"unit_test_app_key"; + [MParticle sharedInstance].stateMachine.secret = @"unit_test_secret"; + + [MParticle sharedInstance].backendController = [[MPBackendController_PRIVATE alloc] initWithDelegate:(id)[MParticle sharedInstance]]; +} + - (void) swizzleInstanceMethodForInstancesOfClass:(Class)targetClass selector:(SEL)selector { originalMethod = class_getInstanceMethod(targetClass, selector); @@ -159,7 +168,7 @@ - (void)testEventURLWithOptionsAndOverrideAndEventsOnlyAndTrackingHost { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *eventURL = [networkCommunication eventURLForUpload:upload].url; [self deswizzle]; @@ -174,7 +183,7 @@ - (void)testAliasURL { [self swizzleInstanceMethodForInstancesOfClass:[NSBundle class] selector:@selector(infoDictionary)]; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -190,7 +199,7 @@ - (void)testAliasURLWithOptions { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -207,7 +216,7 @@ - (void)testAliasURLWithOptionsAndOverride { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -226,7 +235,7 @@ - (void)testAliasURLWithEventsOnly { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -244,7 +253,7 @@ - (void)testAliasURLWithOptionsAndEventsOnly { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -263,7 +272,7 @@ - (void)testAliasURLWithOptionsAndOverrideAndEventsOnly { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -289,7 +298,7 @@ - (void)testAliasURLWithOptionsAndOverrideAndEventsOnlyAndTrackingHost { [MParticle sharedInstance].networkOptions = options; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSURL *aliasURL = [networkCommunication aliasURLForUpload:upload].url; [self deswizzle]; @@ -312,7 +321,7 @@ - (void)testEmptyUploadsArray { - (void)testUploadsArrayZipFail { MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSArray *uploads = @[upload]; id mockZip = OCMClassMock([MPZip_PRIVATE class]); OCMStub([mockZip compressedDataFromData:OCMOCK_ANY]).andReturn(nil); @@ -327,7 +336,7 @@ - (void)testUploadsArrayZipSucceedWithATTNotDetermined { [[MParticle sharedInstance] setATTStatus:MPATTAuthorizationStatusNotDetermined withATTStatusTimestampMillis:nil]; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSArray *uploads = @[upload]; id mockZip = OCMClassMock([MPZip_PRIVATE class]); [[mockZip expect] compressedDataFromData:[OCMArg checkWithBlock:^BOOL(id value) { @@ -344,7 +353,7 @@ - (void)testUploadsArrayZipSucceedWithATTRestricted { [[MParticle sharedInstance] setATTStatus:MPATTAuthorizationStatusRestricted withATTStatusTimestampMillis:nil]; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSArray *uploads = @[upload]; id mockZip = OCMClassMock([MPZip_PRIVATE class]); [[mockZip expect] compressedDataFromData:[OCMArg checkWithBlock:^BOOL(id value) { @@ -361,7 +370,7 @@ - (void)testUploadsArrayZipSucceedWithATTDenied { [[MParticle sharedInstance] setATTStatus:MPATTAuthorizationStatusDenied withATTStatusTimestampMillis:nil]; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSArray *uploads = @[upload]; id mockZip = OCMClassMock([MPZip_PRIVATE class]); [[mockZip expect] compressedDataFromData:[OCMArg checkWithBlock:^BOOL(id value) { @@ -378,7 +387,7 @@ - (void)testUploadsArrayZipSucceedWithATTAuthorized { [[MParticle sharedInstance] setATTStatus:MPATTAuthorizationStatusAuthorized withATTStatusTimestampMillis:nil]; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; NSArray *uploads = @[upload]; id mockZip = OCMClassMock([MPZip_PRIVATE class]); [[mockZip expect] compressedDataFromData:[OCMArg checkWithBlock:^BOOL(id value) { @@ -420,7 +429,7 @@ - (void)shouldStopEvents:(int)returnCode shouldStop:(BOOL)shouldStop { id mockNetworkCommunication = OCMPartialMock(networkCommunication); [[[mockNetworkCommunication stub] andReturn:mockConnector] makeConnector]; - MPUpload *messageUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *messageUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; BOOL actualShouldStop = [networkCommunication performMessageUpload:messageUpload]; XCTAssertEqual(shouldStop, actualShouldStop, @"Return code assertion: %d", returnCode); @@ -455,7 +464,7 @@ - (void)shouldStopAlias:(int)returnCode shouldStop:(BOOL)shouldStop { id mockNetworkCommunication = OCMPartialMock(networkCommunication); [[[mockNetworkCommunication stub] andReturn:mockConnector] makeConnector]; - MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; aliasUpload.uploadType = MPUploadTypeAlias; BOOL actualShouldStop = [networkCommunication performAliasUpload:aliasUpload]; @@ -476,14 +485,14 @@ - (void)testOfflineUpload { id mockNetworkCommunication = OCMPartialMock(networkCommunication); [[[mockNetworkCommunication stub] andReturn:mockConnector] makeConnector]; - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); [[mockPersistenceController reject] deleteUpload:OCMOCK_ANY]; MParticle *instance = [MParticle sharedInstance]; instance.persistenceController = mockPersistenceController; - MPUpload *eventUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; - MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *eventUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; + MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; aliasUpload.uploadType = MPUploadTypeAlias; NSArray *uploads = @[eventUpload, aliasUpload]; @@ -508,10 +517,10 @@ - (void)testUploadSuccessDeletion { id mockNetworkCommunication = OCMPartialMock(networkCommunication); [[[mockNetworkCommunication stub] andReturn:mockConnector] makeConnector]; - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); - MPUpload *eventUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; - MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *eventUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{kMPDeviceInformationKey: @{}} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; + MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; aliasUpload.uploadType = MPUploadTypeAlias; [[mockPersistenceController expect] deleteUpload:eventUpload]; @@ -550,10 +559,10 @@ - (void)testUploadInvalidDeletion { id mockNetworkCommunication = OCMPartialMock(networkCommunication); [[[mockNetworkCommunication stub] andReturn:mockConnector] makeConnector]; - id mockPersistenceController = OCMClassMock([MPPersistenceController class]); + id mockPersistenceController = OCMClassMock([MPPersistenceController_PRIVATE class]); - MPUpload *eventUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; - MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *eventUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; + MPUpload *aliasUpload = [[MPUpload alloc] initWithSessionId:@1 uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; aliasUpload.uploadType = MPUploadTypeAlias; [[mockPersistenceController expect] deleteUpload:eventUpload]; @@ -575,7 +584,7 @@ - (void)testUploadInvalidDeletion { } - (void)testRequestConfigWithDefaultMaxAge { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSNumber *configProvisioned = userDefaults[kMPConfigProvisionedTimestampKey]; NSNumber *maxAge = userDefaults[kMPConfigMaxAgeHeaderKey]; @@ -635,7 +644,7 @@ - (void)testRequestConfigWithDefaultMaxAge { } - (void)testRequestConfigWithManualMaxAge { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPConfigProvisionedTimestampKey] = @5555; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; @@ -739,7 +748,7 @@ - (void)testRequestConfigWithManualMaxAgeAndInitialAge { XCTAssert(success); }]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults synchronize]; NSNumber *provisionedInterval = userDefaults[kMPConfigProvisionedTimestampKey]; @@ -750,7 +759,7 @@ - (void)testRequestConfigWithManualMaxAgeAndInitialAge { } - (void)testRequestConfigWithManualMaxAgeOverMaxAllowed { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPConfigProvisionedTimestampKey] = @5555; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; @@ -807,7 +816,7 @@ - (void)testRequestConfigWithManualMaxAgeOverMaxAllowed { } - (void)testRequestConfigWithComplexCacheControlHeader { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPConfigProvisionedTimestampKey] = @5555; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; diff --git a/UnitTests/MPPersistenceControllerTests.mm b/UnitTests/MPPersistenceControllerTests.mm index f8b9989a3..619829937 100644 --- a/UnitTests/MPPersistenceControllerTests.mm +++ b/UnitTests/MPPersistenceControllerTests.mm @@ -13,15 +13,15 @@ #import "MPUploadBuilder.h" #import "MPDatabaseMigrationController.h" #import -#import "MPIUserDefaults.h" #import "MPBaseTestCase.h" #import "MPStateMachine.h" #import "MPKitFilter.h" +#import "MParticleSwift.h" @interface MParticle () + (dispatch_queue_t)messageQueue; -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, nullable) NSString *dataPlanId; @property (nonatomic, strong, nullable) NSNumber *dataPlanVersion; @@ -45,7 +45,7 @@ @implementation MPPersistenceControllerTests - (void)setUp { [super setUp]; - [MParticle sharedInstance].persistenceController = [[MPPersistenceController alloc] init]; + [MParticle sharedInstance].persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; MPStateMachine_PRIVATE *stateMachine = [[MPStateMachine_PRIVATE alloc] init]; stateMachine.apiKey = @"test_key"; stateMachine.secret = @"test_secret"; @@ -57,9 +57,9 @@ - (void)testMultiThreadedAccess { NSDate *endDate = [startDate dateByAddingTimeInterval:0.1]; dispatch_block_t workBlock = ^{ while (-[[NSDate date] timeIntervalSinceDate:endDate] > 0) { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveSession:session]; NSMutableArray *sessions = [persistence fetchSessions]; [persistence deleteSession:session]; @@ -76,7 +76,7 @@ - (void)testMultiThreadedAccess { } - (void)testMigrateMessagesWithNullSessions { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @"key3":@"value3"}; @@ -91,7 +91,7 @@ - (void)testMigrateMessagesWithNullSessions { } - (void)testMigrateUploadsWithNullSessions { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @"key3":@"value3"}; @@ -100,7 +100,7 @@ - (void)testMigrateUploadsWithNullSessions { session:nil messageInfo:messageInfo]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:@123 sessionId:nil messages:@[[messageBuilder build]] sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:@123 sessionId:nil messages:@[[messageBuilder build]] sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; __block BOOL tested = NO; [uploadBuilder build:^(MPUpload * _Nullable upload) { [persistence saveUpload:upload]; @@ -112,7 +112,7 @@ - (void)testMigrateUploadsWithNullSessions { } - (void)testMigrateMessagesWithSessions { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @"key3":@"value3"}; @@ -137,7 +137,7 @@ - (void)testMigrateMessagesWithSessions { } - (void)testMigrateUploadsWithSessions { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @"key3":@"value3"}; @@ -148,7 +148,7 @@ - (void)testMigrateUploadsWithSessions { session:session messageInfo:messageInfo]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:@123 sessionId:@11 messages:@[[messageBuilder build]] sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:@123 sessionId:@11 messages:@[[messageBuilder build]] sessionTimeout:100 uploadInterval:100 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; __block BOOL tested = NO; [uploadBuilder build:^(MPUpload * _Nullable upload) { [persistence saveUpload:upload]; @@ -172,10 +172,10 @@ - (void)testMigrateUploadsWithSessions { - (void)testSession { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; session.attributesDictionary = [@{@"key1":@"value1"} mutableCopy]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveSession:session]; XCTAssertTrue(session.sessionId > 0, @"Session id not greater than zero: %lld", session.sessionId); @@ -195,11 +195,11 @@ - (void)testSession { } - (void)testMessage { - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; [persistence saveSession:session]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent @@ -211,7 +211,7 @@ - (void)testMessage { XCTAssertTrue(message.messageId > 0, @"Message id not greater than zero: %lld", message.messageId); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -223,7 +223,7 @@ - (void)testMessage { [persistence deleteSession:session]; messagesDictionary = [persistence fetchMessagesForUploading]; - messages = messagesDictionary[[MPPersistenceController mpId]]; + messages = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; if (messages) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"messageId == %lld", fetchedMessage.messageId]; messages = [messages filteredArrayUsingPredicate:predicate]; @@ -234,11 +234,11 @@ - (void)testMessage { - (void)testMessageWithDataPlan { [MParticle sharedInstance].dataPlanId = @"test"; [MParticle sharedInstance].dataPlanVersion = @(1); - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; [persistence saveSession:session]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent @@ -250,7 +250,7 @@ - (void)testMessageWithDataPlan { XCTAssertTrue(message.messageId > 0, @"Message id not greater than zero: %lld", message.messageId); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"test"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:1]]; @@ -262,7 +262,7 @@ - (void)testMessageWithDataPlan { [persistence deleteSession:session]; messagesDictionary = [persistence fetchMessagesForUploading]; - messages = messagesDictionary[[MPPersistenceController mpId]]; + messages = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; if (messages) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"messageId == %lld", fetchedMessage.messageId]; messages = [messages filteredArrayUsingPredicate:predicate]; @@ -272,11 +272,11 @@ - (void)testMessageWithDataPlan { - (void)testMessageWithDataPlanNoVersion { [MParticle sharedInstance].dataPlanId = @"test"; - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; [persistence saveSession:session]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent @@ -288,7 +288,7 @@ - (void)testMessageWithDataPlanNoVersion { XCTAssertTrue(message.messageId > 0, @"Message id not greater than zero: %lld", message.messageId); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"test"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -300,7 +300,7 @@ - (void)testMessageWithDataPlanNoVersion { [persistence deleteSession:session]; messagesDictionary = [persistence fetchMessagesForUploading]; - messages = messagesDictionary[[MPPersistenceController mpId]]; + messages = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; if (messages) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"messageId == %lld", fetchedMessage.messageId]; messages = [messages filteredArrayUsingPredicate:predicate]; @@ -309,11 +309,11 @@ - (void)testMessageWithDataPlanNoVersion { } - (void)testResetDatabase { - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; [persistence saveSession:session]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent @@ -325,7 +325,7 @@ - (void)testResetDatabase { XCTAssertTrue(message.messageId > 0, @"Message id not greater than zero: %lld", message.messageId); NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -337,7 +337,7 @@ - (void)testResetDatabase { [[MParticle sharedInstance].persistenceController resetDatabase]; messagesDictionary = [persistence fetchMessagesForUploading]; - messages = messagesDictionary[[MPPersistenceController mpId]]; + messages = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; if (messages) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"messageId == %lld", fetchedMessage.messageId]; messages = [messages filteredArrayUsingPredicate:predicate]; @@ -347,7 +347,7 @@ - (void)testResetDatabase { } - (void)testUpload { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -361,9 +361,9 @@ - (void)testUpload { kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveUpload:upload]; @@ -394,7 +394,7 @@ - (void)testUploadWithDataPlan { [MParticle sharedInstance].dataPlanId = @"test"; [MParticle sharedInstance].dataPlanVersion = @(1); - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -408,9 +408,9 @@ - (void)testUploadWithDataPlan { kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveUpload:upload]; @@ -440,7 +440,7 @@ - (void)testUploadWithDataPlan { - (void)testUploadWithDataPlanNoVersion { [MParticle sharedInstance].dataPlanId = @"test"; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session @@ -454,9 +454,9 @@ - (void)testUploadWithDataPlanNoVersion { kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:@"test" dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:[NSNumber numberWithLongLong:session.sessionId] uploadDictionary:uploadDictionary dataPlanId:@"test" dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveUpload:upload]; @@ -487,17 +487,17 @@ - (void)testUploadWithOptOut { XCTestExpectation *expectation = [self expectationWithDescription:@"Upload Opt Out test"]; [MParticle sharedInstance].stateMachine.optOut = YES; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session messageInfo:@{@"MessageKey1":@"MessageValue1"}]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] sessionId:@(session.sessionId) messages:@[message] sessionTimeout:120 uploadInterval:10 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:@(session.sessionId) messages:@[message] sessionTimeout:120 uploadInterval:10 dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; [uploadBuilder build:^(MPUpload *upload) { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveUpload:upload]; @@ -515,16 +515,16 @@ - (void)testUploadWithOptOutMessage { XCTestExpectation *expectation = [self expectationWithDescription:@"Upload Opt Out Message test"]; [MParticle sharedInstance].stateMachine.optOut = YES; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeOptOut session:session messageInfo:@{kMPOptOutStatus:(@"true")}]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] sessionId:@(session.sessionId) messages:@[message] sessionTimeout:120 uploadInterval:10 dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:@(session.sessionId) messages:@[message] sessionTimeout:120 uploadInterval:10 dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; [uploadBuilder build:^(MPUpload *upload) { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveUpload:upload]; @@ -552,7 +552,7 @@ - (void)testUploadWithOptOutMessage { - (void)testFetchIntegrationAttributesForKit { NSNumber *integrationId = nil; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; XCTAssertNil([persistence fetchIntegrationAttributesForId:integrationId]); XCTAssertNil([persistence fetchIntegrationAttributesForId:@1000]); @@ -583,7 +583,7 @@ - (void)testFetchIntegrationAttributesForKit { } - (void)testIntegrationAttributes { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence deleteIntegrationAttributesForIntegrationId:@42]; NSNumber *integrationId = @(MPKitInstanceUrbanAirship); @@ -634,7 +634,7 @@ - (void)testIntegrationAttributes { } - (void)testConsumerInfo { - [MPPersistenceController setMpid:@2]; + [MPPersistenceController_PRIVATE setMpid:@2]; NSDictionary *consumerInfoDictionary = @{ @"ck":@{ @@ -662,13 +662,13 @@ - (void)testConsumerInfo { __block MPConsumerInfo *consumerInfo = [[MPConsumerInfo alloc] init]; [consumerInfo updateWithConfiguration:consumerInfoDictionary]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveConsumerInfo:consumerInfo]; XCTestExpectation *expectation = [self expectationWithDescription:@"Consumer Info"]; dispatch_sync([MParticle messageQueue], ^{ - MPConsumerInfo *fetchedConsumerInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController mpId]]; + MPConsumerInfo *fetchedConsumerInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertNotNil(fetchedConsumerInfo); NSDictionary *cookiesDictionary = [consumerInfo cookiesDictionaryRepresentation]; @@ -676,7 +676,7 @@ - (void)testConsumerInfo { XCTAssertEqualObjects(cookiesDictionary, fetchedCookiesDictionary); [persistence deleteConsumerInfo]; - fetchedConsumerInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController mpId]]; + fetchedConsumerInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertNil(fetchedConsumerInfo); consumerInfo = [[MPConsumerInfo alloc] init]; @@ -684,7 +684,7 @@ - (void)testConsumerInfo { [persistence saveConsumerInfo:consumerInfo]; [persistence updateConsumerInfo:consumerInfo]; - consumerInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController mpId]]; + consumerInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController_PRIVATE mpId]]; XCTAssertNotNil(consumerInfo); [persistence deleteConsumerInfo]; @@ -700,7 +700,7 @@ - (void)testForwardRecord { execStatus:execStatus stateFlag:YES]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; [persistence saveForwardRecord:forwardRecord]; NSArray *forwardRecords = [persistence fetchForwardRecords]; @@ -710,18 +710,18 @@ - (void)testForwardRecord { MPForwardRecord *fetchedForwardRecord = [forwardRecords firstObject]; XCTAssertEqualObjects(forwardRecord, fetchedForwardRecord); - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session messageInfo:@{}]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:@"test" dataPlanVersion:@(1) - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; [uploadBuilder build: ^(MPUpload * _Nullable upload) { }]; @@ -735,16 +735,16 @@ - (void)testTooLargeMessageSaving { while (longString.length < 102401) { longString = [NSString stringWithFormat:@"%@%@", longString, longString]; } - [MPPersistenceController setMpid:@1]; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + [MPPersistenceController_PRIVATE setMpid:@1]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeEvent session:session messageInfo:@{@"MessageKey1":longString}]; MPMessage *message = [messageBuilder build]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -754,7 +754,7 @@ - (void)testTooLargeMessageSaving { [persistence saveMessage:message]; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -767,16 +767,16 @@ - (void)testTooLargeCrashMessageSaving { while (longString.length < 1024001) { longString = [NSString stringWithFormat:@"%@%@", longString, longString]; } - [MPPersistenceController setMpid:@1]; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + [MPPersistenceController_PRIVATE setMpid:@1]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeCrashReport session:session messageInfo:@{@"MessageKey1":longString}]; MPMessage *message = [messageBuilder build]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSDictionary *messagesDictionary = [persistence fetchMessagesForUploading]; - NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + NSMutableDictionary *sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; NSMutableDictionary *dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; NSMutableDictionary *dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; NSArray *messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -786,7 +786,7 @@ - (void)testTooLargeCrashMessageSaving { [persistence saveMessage:message]; messagesDictionary = [persistence fetchMessagesForUploading]; - sessionsDictionary = messagesDictionary[[MPPersistenceController mpId]]; + sessionsDictionary = messagesDictionary[[MPPersistenceController_PRIVATE mpId]]; dataPlanIdDictionary = [sessionsDictionary objectForKey:[NSNumber numberWithLong:session.sessionId]]; dataPlanVersionDictionary = [dataPlanIdDictionary objectForKey:@"0"]; messages = [dataPlanVersionDictionary objectForKey:[NSNumber numberWithInt:0]]; @@ -795,7 +795,7 @@ - (void)testTooLargeCrashMessageSaving { } - (void)testSaveNilMessage { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSException *e = nil; @try { [persistence saveMessage:(id _Nonnull)nil]; @@ -878,7 +878,7 @@ - (void)testDeleteRecordsOlderThan_DontDelete { XCTAssertEqual([instance.persistenceController fetchMessagesForUploading].count, 1); // Store a session - MPSession *session = [[MPSession alloc] initWithStartTime:oneDayAgo userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:oneDayAgo userId:[MPPersistenceController_PRIVATE mpId]]; session.endTime = oneDayAgo; session.attributesDictionary = [@{@"key1":@"value1"} mutableCopy]; [instance.persistenceController saveSession:session]; @@ -886,7 +886,7 @@ - (void)testDeleteRecordsOlderThan_DontDelete { // Store an upload NSDictionary *uploadDictionary = @{kMPOptOutKey:@NO, kMPSessionTimeoutKey:@120, kMPUploadIntervalKey:@10, kMPLifeTimeValueKey:@0, kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@(session.sessionId) uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@(session.sessionId) uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; upload.timestamp = oneDayAgo; [instance.persistenceController saveUpload:upload]; XCTAssertEqual([instance.persistenceController fetchUploads].count, 1); @@ -914,7 +914,7 @@ - (void)testDeleteRecordsOlderThan_Delete { XCTAssertEqual([instance.persistenceController fetchMessagesForUploading].count, 1); // Store a session - MPSession *session = [[MPSession alloc] initWithStartTime:sevenDaysAgo userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:sevenDaysAgo userId:[MPPersistenceController_PRIVATE mpId]]; session.endTime = sevenDaysAgo; session.attributesDictionary = [@{@"key1":@"value1"} mutableCopy]; [instance.persistenceController saveSession:session]; @@ -922,7 +922,7 @@ - (void)testDeleteRecordsOlderThan_Delete { // Store an upload NSDictionary *uploadDictionary = @{kMPOptOutKey:@NO, kMPSessionTimeoutKey:@120, kMPUploadIntervalKey:@10, kMPLifeTimeValueKey:@0, kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@(session.sessionId) uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@(session.sessionId) uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; upload.timestamp = sevenDaysAgo; [instance.persistenceController saveUpload:upload]; XCTAssertEqual([instance.persistenceController fetchUploads].count, 1); @@ -949,7 +949,7 @@ - (void)testClearDatabaseForWorkspaceSwitching { XCTAssertEqual([instance.persistenceController fetchMessagesForUploading].count, 1); // Store a session - MPSession *session = [[MPSession alloc] initWithStartTime:sevenDaysAgo userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:sevenDaysAgo userId:[MPPersistenceController_PRIVATE mpId]]; session.endTime = sevenDaysAgo; session.attributesDictionary = [@{@"key1":@"value1"} mutableCopy]; [instance.persistenceController saveSession:session]; @@ -957,7 +957,7 @@ - (void)testClearDatabaseForWorkspaceSwitching { // Store an upload NSDictionary *uploadDictionary = @{kMPOptOutKey:@NO, kMPSessionTimeoutKey:@120, kMPUploadIntervalKey:@10, kMPLifeTimeValueKey:@0, kMPMessagesKey:@[[message dictionaryRepresentation]], kMPMessageIdKey:[[NSUUID UUID] UUIDString]}; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:@(session.sessionId) uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:@(session.sessionId) uploadDictionary:uploadDictionary dataPlanId:nil dataPlanVersion:nil uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; upload.timestamp = sevenDaysAgo; [instance.persistenceController saveUpload:upload]; XCTAssertEqual([instance.persistenceController fetchUploads].count, 1); diff --git a/UnitTests/MPResponseConfigTests.m b/UnitTests/MPResponseConfigTests.m index 3c44032f1..ce1f4d174 100644 --- a/UnitTests/MPResponseConfigTests.m +++ b/UnitTests/MPResponseConfigTests.m @@ -3,7 +3,6 @@ #import "MParticleSwift.h" #import "MPIConstants.h" #import "MPStateMachine.h" -#import "MPIUserDefaults.h" #import "MPBaseTestCase.h" @interface MParticle () @@ -11,7 +10,7 @@ @interface MParticle () + (dispatch_queue_t)messageQueue; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, nonnull) MParticleOptions *options; -@property (nonatomic, strong, readonly) MPBackendController_PRIVATE *backendController; +@property (nonatomic, strong) MPBackendController_PRIVATE *backendController; @end @@ -21,6 +20,14 @@ @interface MPResponseConfigTests : MPBaseTestCase @implementation MPResponseConfigTests +- (void)setUp { + [super setUp]; + + [MParticle sharedInstance].stateMachine.apiKey = @"unit_test_app_key"; + [MParticle sharedInstance].stateMachine.secret = @"unit_test_secret"; + + [MParticle sharedInstance].backendController = [[MPBackendController_PRIVATE alloc] initWithDelegate:(id)[MParticle sharedInstance]]; +} - (void)testInstance { NSDictionary *configuration = @{kMPRemoteConfigKitsKey:[NSNull null], kMPRemoteConfigCustomModuleSettingsKey:[NSNull null], @@ -81,13 +88,13 @@ - (void)testSaveRestore { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; configuration = @{kMPRemoteConfigRampKey:@100, kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, kMPRemoteConfigSessionTimeoutKey:@112}; - MPResponseConfig *restoredResponseConfig = [MPIUserDefaults restore]; + MPResponseConfig *restoredResponseConfig = [MPUserDefaults restore]; XCTAssertNotNil(restoredResponseConfig); XCTAssertEqualObjects(restoredResponseConfig.configuration, configuration); @@ -110,11 +117,11 @@ - (void)testShouldDeleteDueToMaxConfigAgeWhenNil { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - XCTAssertFalse([MPIUserDefaults isOlderThanConfigMaxAgeSeconds]); + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; + XCTAssertFalse([MPUserDefaults isOlderThanConfigMaxAgeSeconds]); - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:(requestTimestamp - 10000.0) currentAge:@"0" maxAge:nil]; - XCTAssertFalse([MPIUserDefaults isOlderThanConfigMaxAgeSeconds]); + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:(requestTimestamp - 10000.0) currentAge:0 maxAge:nil]; + XCTAssertFalse([MPUserDefaults isOlderThanConfigMaxAgeSeconds]); [expectation fulfill]; }); @@ -135,11 +142,11 @@ - (void)testShouldDeleteDueToMaxConfigAge { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - XCTAssertFalse([MPIUserDefaults isOlderThanConfigMaxAgeSeconds]); + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; + XCTAssertFalse([MPUserDefaults isOlderThanConfigMaxAgeSeconds]); - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:(requestTimestamp - 100.0) currentAge:@"0" maxAge:nil]; - XCTAssertTrue([MPIUserDefaults isOlderThanConfigMaxAgeSeconds]); + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:(requestTimestamp - 100.0) currentAge:0 maxAge:nil]; + XCTAssertTrue([MPUserDefaults isOlderThanConfigMaxAgeSeconds]); [expectation fulfill]; }); @@ -159,16 +166,16 @@ - (void)testDeleteDueToMaxConfigAge { kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, kMPRemoteConfigSessionTimeoutKey:@112}; - XCTAssertNil([[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertNil([[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970] - 100.0; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - XCTAssertNotNil([[MPIUserDefaults standardUserDefaults] getConfiguration]); + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; + XCTAssertNotNil([[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); - XCTAssertTrue([MPIUserDefaults isOlderThanConfigMaxAgeSeconds]); - if ([MPIUserDefaults isOlderThanConfigMaxAgeSeconds]) { - [MPIUserDefaults deleteConfig]; + XCTAssertTrue([MPUserDefaults isOlderThanConfigMaxAgeSeconds]); + if ([MPUserDefaults isOlderThanConfigMaxAgeSeconds]) { + [MPUserDefaults deleteConfig]; } - XCTAssertNil([[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertNil([[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); [expectation fulfill]; }); diff --git a/UnitTests/MPResponseEventsTest.m b/UnitTests/MPResponseEventsTest.m index 975fb7a3b..c0443ae30 100644 --- a/UnitTests/MPResponseEventsTest.m +++ b/UnitTests/MPResponseEventsTest.m @@ -47,10 +47,10 @@ - (void)testParseConfiguration { NSString *newDas = @"abcd1234"; stateMachine.consumerInfo.uniqueIdentifier = originalDas; - [MPPersistenceController setMpid:originalMpId]; + [MPPersistenceController_PRIVATE setMpid:originalMpId]; stateMachine.consumerInfo.cookies = originalCookies; - XCTAssertEqualObjects([MPPersistenceController mpId], originalMpId); + XCTAssertEqualObjects([MPPersistenceController_PRIVATE mpId], originalMpId); XCTAssertEqualObjects(stateMachine.consumerInfo.uniqueIdentifier, originalDas); XCTAssertTrue(areEqual(stateMachine.consumerInfo.cookiesDictionaryRepresentation, originalCookies)); @@ -61,7 +61,7 @@ - (void)testParseConfiguration { }}; [MPNetworkCommunication_PRIVATE parseConfiguration:response]; - XCTAssertEqualObjects([MPPersistenceController mpId], originalMpId); + XCTAssertEqualObjects([MPPersistenceController_PRIVATE mpId], originalMpId); XCTAssertEqualObjects(stateMachine.consumerInfo.uniqueIdentifier, originalDas); XCTAssertTrue(areEqual(stateMachine.consumerInfo.cookiesDictionaryRepresentation, originalCookies)); } diff --git a/UnitTests/MPURLRequestBuilderTests.m b/UnitTests/MPURLRequestBuilderTests.m index 4275a1c92..9eeaac82a 100644 --- a/UnitTests/MPURLRequestBuilderTests.m +++ b/UnitTests/MPURLRequestBuilderTests.m @@ -10,7 +10,6 @@ #import "MPKitRegister.h" #import "MPKitContainer.h" #import "MPKitTestClass.h" -#import "MPIUserDefaults.h" #import "MPPersistenceController.h" #import "MPMessage.h" #import "MPBaseTestCase.h" @@ -25,6 +24,7 @@ @interface MParticle () + (dispatch_queue_t)messageQueue; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; @property (nonatomic, strong) MParticleWebView_PRIVATE *webView; @@ -61,7 +61,7 @@ @implementation MPURLRequestBuilderTests - (void)setUp { [super setUp]; - [MPPersistenceController setMpid:@12]; + [MPPersistenceController_PRIVATE setMpid:@12]; [MParticle sharedInstance].stateMachine.apiKey = @"unit_test_app_key"; [MParticle sharedInstance].stateMachine.secret = @"unit_test_secret"; @@ -106,8 +106,8 @@ - (void)testCustomUserAgent { MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPMessage *message = [[MPMessage alloc] initWithSession:nil messageType:@"e" messageInfo:@{@"key":@"value"} uploadStatus:MPUploadStatusBatch UUID:[[NSUUID UUID] UUIDString] timestamp:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId] dataPlanId:@"test" dataPlanVersion:@(1)]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPMessage *message = [[MPMessage alloc] initWithSession:nil messageType:@"e" messageInfo:@{@"key":@"value"} uploadStatus:MPUploadStatusBatch UUID:[[NSUUID UUID] UUIDString] timestamp:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId] dataPlanId:@"test" dataPlanVersion:@(1)]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; MPURLRequestBuilder *urlRequestBuilder = [MPURLRequestBuilder newBuilderWithURL:[networkCommunication eventURLForUpload:upload] message:[message serializedString] @@ -133,8 +133,8 @@ - (void)testDisableCollectUserAgent { MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPMessage *message = [[MPMessage alloc] initWithSession:nil messageType:@"e" messageInfo:@{@"key":@"value"} uploadStatus:MPUploadStatusBatch UUID:[[NSUUID UUID] UUIDString] timestamp:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId] dataPlanId:@"test" dataPlanVersion:@(1)]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPMessage *message = [[MPMessage alloc] initWithSession:nil messageType:@"e" messageInfo:@{@"key":@"value"} uploadStatus:MPUploadStatusBatch UUID:[[NSUUID UUID] UUIDString] timestamp:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId] dataPlanId:@"test" dataPlanVersion:@(1)]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; MPURLRequestBuilder *urlRequestBuilder = [MPURLRequestBuilder newBuilderWithURL:[networkCommunication eventURLForUpload:upload] message:[message serializedString] @@ -249,7 +249,7 @@ - (void)testEtag { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; MPURLRequestBuilder *urlRequestBuilder = [MPURLRequestBuilder newBuilderWithURL:[networkCommunication configURL] message:nil httpMethod:@"GET"]; @@ -400,8 +400,8 @@ - (void)testEventRequest { MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc] init]; - MPMessage *message = [[MPMessage alloc] initWithSession:nil messageType:@"e" messageInfo:@{@"key":@"value"} uploadStatus:MPUploadStatusBatch UUID:[[NSUUID UUID] UUIDString] timestamp:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId] dataPlanId:@"test" dataPlanVersion:@(1)]; - MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettings]]; + MPMessage *message = [[MPMessage alloc] initWithSession:nil messageType:@"e" messageInfo:@{@"key":@"value"} uploadStatus:MPUploadStatusBatch UUID:[[NSUUID UUID] UUIDString] timestamp:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId] dataPlanId:@"test" dataPlanVersion:@(1)]; + MPUpload *upload = [[MPUpload alloc] initWithSessionId:nil uploadDictionary:@{} dataPlanId:@"test" dataPlanVersion:@(1) uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; MPURLRequestBuilder *urlRequestBuilder = [MPURLRequestBuilder newBuilderWithURL:[networkCommunication eventURLForUpload:upload] message:[message serializedString] diff --git a/UnitTests/MPUploadBuilderTests.m b/UnitTests/MPUploadBuilderTests.m index de2d28a22..75b240a26 100644 --- a/UnitTests/MPUploadBuilderTests.m +++ b/UnitTests/MPUploadBuilderTests.m @@ -11,10 +11,11 @@ #import "MPBaseTestCase.h" #import "MPDevice.h" #import "mParticle.h" +#import "MParticleSwift.h" @interface MParticle () -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, nullable) NSString *dataPlanId; @property (nonatomic, strong, nullable) NSNumber *dataPlanVersion; @@ -37,8 +38,8 @@ @implementation MPUploadBuilderTests - (void)setUp { [super setUp]; - [MParticle sharedInstance].persistenceController = [[MPPersistenceController alloc] init]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + [MParticle sharedInstance].persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSNumber *integrationId = @(MPKitInstanceUrbanAirship); NSDictionary *attributes = @{@"clientID":@"123abc", @@ -115,7 +116,7 @@ - (void)configureCustomModules { - (void)testInstanceWithSession { XCTestExpectation *expectation = [self expectationWithDescription:@"Upload builder instance (session)"]; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -130,14 +131,14 @@ - (void)testInstanceWithSession { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -204,14 +205,14 @@ - (void)testInstanceWithoutSession { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:nil messages:@[message] sessionTimeout:0 uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -269,7 +270,7 @@ - (void)testInstanceWithDataPlanId { [MParticle sharedInstance].dataPlanId = @"test"; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -284,14 +285,14 @@ - (void)testInstanceWithDataPlanId { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -351,7 +352,7 @@ - (void)testInstanceWithDataPlanVersion { [MParticle sharedInstance].dataPlanId = @"test"; [MParticle sharedInstance].dataPlanVersion = @1; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -366,14 +367,14 @@ - (void)testInstanceWithDataPlanVersion { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -430,7 +431,7 @@ - (void)testInstanceWithDataPlanVersion { - (void)testInstanceWithAdvertiserIdInSessionNoAttStatus { XCTestExpectation *expectation = [self expectationWithDescription:@"Upload builder instance (session)"]; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -445,14 +446,14 @@ - (void)testInstanceWithAdvertiserIdInSessionNoAttStatus { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -512,7 +513,7 @@ - (void)testInstanceWithAdvertiserIdInSessionAuthorizedAttStatus { [[MParticle sharedInstance] setATTStatus:MPATTAuthorizationStatusAuthorized withATTStatusTimestampMillis:nil]; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -527,14 +528,14 @@ - (void)testInstanceWithAdvertiserIdInSessionAuthorizedAttStatus { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -597,7 +598,7 @@ - (void)testInstanceWithAdvertiserIdInSessionDeniedAttStatus { [[MParticle sharedInstance] setATTStatus:MPATTAuthorizationStatusDenied withATTStatusTimestampMillis:nil]; - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -612,14 +613,14 @@ - (void)testInstanceWithAdvertiserIdInSessionDeniedAttStatus { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); @@ -678,7 +679,7 @@ - (void)testInstanceWithAdvertiserIdInSessionDeniedAttStatus { } - (MPUploadBuilder *)createTestUploadBuilder { - MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController mpId]]; + MPSession *session = [[MPSession alloc] initWithStartTime:[[NSDate date] timeIntervalSince1970] userId:[MPPersistenceController_PRIVATE mpId]]; NSDictionary *messageInfo = @{@"key1":@"value1", @"key2":@"value2", @@ -693,14 +694,14 @@ - (MPUploadBuilder *)createTestUploadBuilder { [messageBuilder timestamp:[[NSDate date] timeIntervalSince1970]]; MPMessage *message = [messageBuilder build]; - MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController mpId] + MPUploadBuilder *uploadBuilder = [[MPUploadBuilder alloc] initWithMpid:[MPPersistenceController_PRIVATE mpId] sessionId:[NSNumber numberWithLong:session.sessionId] messages:@[message] sessionTimeout:DEFAULT_SESSION_TIMEOUT uploadInterval:DEFAULT_UPLOAD_INTERVAL dataPlanId:message.dataPlanId dataPlanVersion:message.dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; XCTAssertNotNil(uploadBuilder); diff --git a/UnitTests/MPIUserDefaultsTests.m b/UnitTests/MPUserDefaultsTests.m similarity index 61% rename from UnitTests/MPIUserDefaultsTests.m rename to UnitTests/MPUserDefaultsTests.m index ef3353cc1..a0fa4fa92 100644 --- a/UnitTests/MPIUserDefaultsTests.m +++ b/UnitTests/MPUserDefaultsTests.m @@ -1,27 +1,28 @@ #import -#import "MPIUserDefaults.h" #import "MPIConstants.h" #import "mParticle.h" #import "MPPersistenceController.h" #import "MPBaseTestCase.h" #import "MPKitContainer.h" #import "MPStateMachine.h" +#import "MParticleSwift.h" @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; @end -@interface MPIUserDefaultsTests : MPBaseTestCase { +@interface MPUserDefaultsTests : MPBaseTestCase { MPKitContainer_PRIVATE *kitContainer; } @end -@implementation MPIUserDefaultsTests +@implementation MPUserDefaultsTests - (void)setUp { [super setUp]; @@ -31,6 +32,8 @@ - (void)setUp { [MParticle sharedInstance].kitContainer_PRIVATE = [[MPKitContainer_PRIVATE alloc] init]; kitContainer = [MParticle sharedInstance].kitContainer_PRIVATE; + + [MParticle sharedInstance].backendController = [[MPBackendController_PRIVATE alloc] initWithDelegate:(id)[MParticle sharedInstance]]; } - (void)tearDown { @@ -39,15 +42,15 @@ - (void)tearDown { } kitContainer = nil; - [[MPIUserDefaults standardUserDefaults] setSharedGroupIdentifier:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setSharedGroupIdentifier:nil]; - [[MPIUserDefaults standardUserDefaults] resetDefaults]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] resetDefaults]; [super tearDown]; } - (void)testUserIDsInUserDefaults { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:[NSDate date] forKey:@"lud" userId:@1]; [userDefaults setMPObject:[NSDate date] forKey:@"lud" userId:[NSNumber numberWithLongLong:INT64_MAX]]; @@ -62,7 +65,7 @@ - (void)testUserIDsInUserDefaults { } - (void)testResetDefaults { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:[NSDate date] forKey:@"lud" userId:@1]; [userDefaults setMPObject:[NSDate date] forKey:@"lud" userId:[NSNumber numberWithLongLong:INT64_MAX]]; @@ -82,7 +85,7 @@ - (void)testResetDefaults { } - (void)testMigrate { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setObject:@"test" forKeyedSubscript:@"mparticleKey"]; @@ -95,7 +98,7 @@ - (void)testMigrate { } - (void)testMigrateGroupDoesNotMigrateClientDefaults { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [[NSUserDefaults standardUserDefaults] setObject:@"clientSetting" forKey:@"clientKey"]; @@ -106,7 +109,7 @@ - (void)testMigrateGroupDoesNotMigrateClientDefaults { } - (void)testMigrateGroupWithMultipleUsers { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; [userDefaults setMPObject:[NSDate date] forKey:@"lud" userId:@1]; [userDefaults setMPObject:[NSDate date] forKey:@"lud" userId:[NSNumber numberWithLongLong:INT64_MAX]]; @@ -122,7 +125,7 @@ - (void)testMigrateGroupWithMultipleUsers { } - (void)testValidConfiguration { - [MPPersistenceController setMpid:@12]; + [MPPersistenceController_PRIVATE setMpid:@12]; NSDictionary *configuration1 = @{ @"id":@42, @@ -147,43 +150,9 @@ - (void)testValidConfiguration { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); -} - -- (void)testInvalidConfigurations { - [MPPersistenceController setMpid:@12]; - - NSDictionary *configuration1 = @{ - @"id":@42, - @"as":@{ - @"appId":@"cool app key" - } - }; - - NSDictionary *configuration2 = @{ - @"id":@312, - @"as":@{ - @"appId":@"cool app key 2" - } - }; - - NSArray *kitConfigs = @[configuration1, configuration2]; - - NSString *eTag = @"1.618-2.718-3.141-42"; - NSDictionary *responseConfiguration = @{kMPRemoteConfigKitsKey:kitConfigs, - kMPRemoteConfigRampKey:@100, - kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, - kMPRemoteConfigSessionTimeoutKey:@112}; - - NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - NSDictionary *responseDictionary = nil; - - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseDictionary eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertEqualObjects(responseConfiguration, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); } - (void)testUpdateConfigurations { @@ -203,10 +172,10 @@ - (void)testUpdateConfigurations { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertNotEqualObjects(nil, [[MPIUserDefaults standardUserDefaults] getConfiguration]); - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertNotEqualObjects(nil, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); + XCTAssertEqualObjects(responseConfiguration, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); NSDictionary *configuration2 = @{ @"id":@312, @@ -221,14 +190,14 @@ - (void)testUpdateConfigurations { kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, kMPRemoteConfigSessionTimeoutKey:@112}; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration2 eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:responseConfiguration2 eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertNotEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); - XCTAssertEqualObjects(responseConfiguration2, [[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertNotEqualObjects(responseConfiguration, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); + XCTAssertEqualObjects(responseConfiguration2, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); } - (void)testValidExpandedConfiguration { - [MPPersistenceController setMpid:@12]; + [MPPersistenceController_PRIVATE setMpid:@12]; NSDictionary *configuration1 = @{ @"id":@42, @@ -252,9 +221,9 @@ - (void)testValidExpandedConfiguration { kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, kMPRemoteConfigSessionTimeoutKey:@112}; - MPIUserDefaults *standardDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *standardDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"4000" maxAge:@90000]; + [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:4000 maxAge:@90000]; XCTAssertEqualObjects(responseConfiguration, [standardDefaults getConfiguration]); XCTAssertEqualObjects(standardDefaults[kMPConfigProvisionedTimestampKey], @(requestTimestamp - 4000)); @@ -262,7 +231,7 @@ - (void)testValidExpandedConfiguration { } - (void)testValidExpandedConfigurationWithNilCurrentAge { - [MPPersistenceController setMpid:@12]; + [MPPersistenceController_PRIVATE setMpid:@12]; NSDictionary *configuration1 = @{ @"id":@42, @@ -286,10 +255,10 @@ - (void)testValidExpandedConfigurationWithNilCurrentAge { kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, kMPRemoteConfigSessionTimeoutKey:@112}; - MPIUserDefaults *standardDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *standardDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; NSString *currentAge; - [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:currentAge maxAge:@90000]; + [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:currentAge.doubleValue maxAge:@90000]; XCTAssertEqualObjects(responseConfiguration, [standardDefaults getConfiguration]); XCTAssertEqualObjects(standardDefaults[kMPConfigProvisionedTimestampKey], @(requestTimestamp)); @@ -297,7 +266,7 @@ - (void)testValidExpandedConfigurationWithNilCurrentAge { } - (void)testValidExpandedConfigurationNoMaxAge { - [MPPersistenceController setMpid:@12]; + [MPPersistenceController_PRIVATE setMpid:@12]; NSDictionary *configuration1 = @{ @"id":@42, @@ -321,63 +290,45 @@ - (void)testValidExpandedConfigurationNoMaxAge { kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, kMPRemoteConfigSessionTimeoutKey:@112}; - MPIUserDefaults *standardDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *standardDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"4000" maxAge:@90000]; + [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:4000 maxAge:@90000]; XCTAssertEqualObjects(responseConfiguration, [standardDefaults getConfiguration]); XCTAssertEqualObjects(standardDefaults[kMPConfigProvisionedTimestampKey], @(requestTimestamp - 4000)); XCTAssertEqualObjects(standardDefaults[kMPConfigMaxAgeHeaderKey], @90000); - [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"4000" maxAge:nil]; + [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:4000 maxAge:nil]; XCTAssertEqualObjects(responseConfiguration, [standardDefaults getConfiguration]); XCTAssertEqualObjects(standardDefaults[kMPConfigProvisionedTimestampKey], @(requestTimestamp - 4000)); XCTAssertEqualObjects(standardDefaults[kMPConfigMaxAgeHeaderKey], nil); } -- (void)testInvalidExpandedConfiguration { - [MPPersistenceController setMpid:@12]; - - NSString *eTag = @"1.618-2.718-3.141-42"; - NSDictionary *responseConfiguration; - - MPIUserDefaults *standardDefaults = [MPIUserDefaults standardUserDefaults]; - NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnonnull" - [standardDefaults setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:@90000]; -#pragma clang diagnostic pop - - XCTAssertEqualObjects(nil, [standardDefaults getConfiguration]); - XCTAssertEqualObjects(standardDefaults[kMPConfigProvisionedTimestampKey], nil); - XCTAssertEqualObjects(standardDefaults[kMPConfigMaxAgeHeaderKey], nil); -} - - (void)testDeleteConfiguration { - [[MPIUserDefaults standardUserDefaults] deleteConfiguration]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] deleteConfiguration]; - XCTAssertNil([[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertNil([[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); } - (void)testBadDataConfiguration { - [[MPIUserDefaults standardUserDefaults] deleteConfiguration]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] deleteConfiguration]; NSNumber *userID = [[[MParticle sharedInstance] identity] currentUser].userId; unsigned char ch1[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x04, 0x01, 0x00, 0x0F }; NSData *badData = [[NSData alloc] initWithBytes:ch1 length:sizeof(ch1)]; - [[MPIUserDefaults standardUserDefaults] setMPObject:badData forKey:kMResponseConfigurationKey userId:userID]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setMPObject:badData forKey:kMResponseConfigurationKey userId:userID]; - XCTAssertNil([[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertNil([[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); } - (void)testMigrateConfiguration { NSNumber *userID = [[[MParticle sharedInstance] identity] currentUser].userId; [[NSUserDefaults standardUserDefaults] removeObjectForKey:kMResponseConfigurationMigrationKey]; - [[MPIUserDefaults standardUserDefaults] removeMPObjectForKey:kMPHTTPETagHeaderKey userId:userID]; - [[MPIUserDefaults standardUserDefaults] getConfiguration]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] removeMPObjectForKey:kMPHTTPETagHeaderKey userId:userID]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]; XCTAssertNotNil([[NSUserDefaults standardUserDefaults] objectForKey:kMResponseConfigurationMigrationKey]); } @@ -391,15 +342,15 @@ - (void)testNullConfig { } }; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:configuration1 eTag:@"bar" requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:configuration1 eTag:@"bar" requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertEqualObjects(configuration1, [[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertEqualObjects(configuration1, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); } - (void)testSetConfigurationWhenNil { - XCTAssertEqualObjects(nil, [[MPIUserDefaults standardUserDefaults] getConfiguration]); + XCTAssertEqualObjects(nil, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); - [MPPersistenceController setMpid:@12]; + [MPPersistenceController_PRIVATE setMpid:@12]; NSDictionary *configuration1 = @{ @"id":@42, @@ -424,72 +375,19 @@ - (void)testSetConfigurationWhenNil { kMPRemoteConfigSessionTimeoutKey:@112}; NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); -} - -- (void)testConfigParameters { - XCTAssertEqualObjects(nil, [[MPIUserDefaults standardUserDefaults] getConfiguration]); - XCTAssert([[MPIUserDefaults standardUserDefaults] isConfigurationParametersOutdated]); - - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSString *initialParameters = userDefaults[kMPConfigParameters]; - XCTAssertEqualObjects(nil, initialParameters); - - [MPPersistenceController setMpid:@12]; - - NSDictionary *configuration1 = @{ - @"id":@42, - @"as":@{ - @"appId":@"cool app key" - } - }; - - NSDictionary *configuration2 = @{ - @"id":@312, - @"as":@{ - @"appId":@"cool app key 2" - } - }; - - NSArray *kitConfigs = @[configuration1, configuration2]; - - NSString *eTag = @"1.618-2.718-3.141-42"; - NSDictionary *responseConfiguration = @{kMPRemoteConfigKitsKey:kitConfigs, - kMPRemoteConfigRampKey:@100, - kMPRemoteConfigExceptionHandlingModeKey:kMPRemoteConfigExceptionHandlingModeForce, - kMPRemoteConfigSessionTimeoutKey:@112}; - - NSTimeInterval requestTimestamp = [[NSDate date] timeIntervalSince1970]; - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; - - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); - XCTAssertFalse([[MPIUserDefaults standardUserDefaults] isConfigurationParametersOutdated]); - - NSString *firstParameters = userDefaults[kMPConfigParameters]; - XCTAssertNotNil(firstParameters); - - MPKitRegister *kitRegister = [[MPKitRegister alloc] initWithName:@"KitTest" className:@"MPKitTestClassNoStartImmediately"]; - [MPKitContainer_PRIVATE registerKit:kitRegister]; - - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); - XCTAssertTrue([[MPIUserDefaults standardUserDefaults] isConfigurationParametersOutdated]); - - [[MPIUserDefaults standardUserDefaults] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:@"0" maxAge:nil]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setConfiguration:responseConfiguration eTag:eTag requestTimestamp:requestTimestamp currentAge:0 maxAge:nil]; - XCTAssertEqualObjects(responseConfiguration, [[MPIUserDefaults standardUserDefaults] getConfiguration]); - XCTAssertFalse([[MPIUserDefaults standardUserDefaults] isConfigurationParametersOutdated]); + XCTAssertEqualObjects(responseConfiguration, [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] getConfiguration]); } - (void)testStringFromDeviceToken { NSData *data = [[NSData alloc] init]; - NSString *tokenString = [MPIUserDefaults stringFromDeviceToken:data]; + NSString *tokenString = [MPUserDefaults stringFromDeviceToken:data]; XCTAssertNil(tokenString); data = [NSData dataWithBytes:(unsigned char[]){0x0F} length:1]; - tokenString = [MPIUserDefaults stringFromDeviceToken:data]; + tokenString = [MPUserDefaults stringFromDeviceToken:data]; XCTAssertEqualObjects(tokenString, @"0f"); } diff --git a/UnitTests/MPUserIdentityChangeTests.m b/UnitTests/MPUserIdentityChangeTests.m index 171eca910..0ec1c9499 100644 --- a/UnitTests/MPUserIdentityChangeTests.m +++ b/UnitTests/MPUserIdentityChangeTests.m @@ -2,16 +2,19 @@ #import "MPIdentityApiRequest.h" #import "MParticleUser.h" #import "mParticle.h" -#import "MPIUserDefaults.h" #import "MPIConstants.h" #import "MPBackendController.h" #import "MParticleSwift.h" #import "MPBaseTestCase.h" @interface MParticle () + +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; + @end + @interface MPUserIdentityChangeTests : MPBaseTestCase @end @@ -24,7 +27,7 @@ - (void)testUserIdentityRequest { MParticleUser *currentUser = [[MParticle sharedInstance].identity currentUser]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSArray *userIdentityArray = @[@{@"n" : [NSNumber numberWithLong:MPIdentityCustomerId], @"i" : @"test"}, @{@"n" : [NSNumber numberWithLong:MPIdentityEmail], @"i" : @"test@example.com"}, @{@"n" : [NSNumber numberWithLong:MPIdentityIOSAdvertiserId], @"i" : @"exampleIDFA"}]; [userDefaults setMPObject:userIdentityArray forKey:kMPUserIdentityArrayKey userId:currentUser.userId]; @@ -42,7 +45,7 @@ - (void)testSelectedUserIdentityRequest { NSNumber *selectedUserID = [NSNumber numberWithInteger:58591]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; //Set up Identity to exist [userDefaults setMPObject:[NSDate date] forKey:kMPLastIdentifiedDate userId:selectedUserID]; diff --git a/UnitTests/MParticleTests.m b/UnitTests/MParticleTests.m index 6a15fb74c..8c4377a11 100644 --- a/UnitTests/MParticleTests.m +++ b/UnitTests/MParticleTests.m @@ -7,7 +7,6 @@ #import "MPBackendController.h" #import "MPURLRequestBuilder.h" #import "MPPersistenceController.h" -#import "MPIUserDefaults.h" #import "MPURL.h" #import "MPDevice.h" #import "MPKitContainer.h" @@ -201,7 +200,7 @@ - (void)testNoAutoTrackingManualEndSession { #if TARGET_OS_IOS == 1 - (void)testAutoTrackingContentAvail { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSData *testDeviceToken = [@"<000000000000000000000000000000>" dataUsingEncoding:NSUTF8StringEncoding]; userDefaults[kMPDeviceTokenKey] = testDeviceToken; @@ -341,7 +340,7 @@ - (void)testOptionsConsentStateInitialNil { options.consentState = newConsentState; [instance startWithOptions:options]; dispatch_async([MParticle messageQueue], ^{ - MPConsentState *storedConsentState = [MPPersistenceController consentStateForMpid:[MPPersistenceController mpId]]; + MPConsentState *storedConsentState = [MPPersistenceController_PRIVATE consentStateForMpid:[MPPersistenceController_PRIVATE mpId]]; XCTAssert(storedConsentState.ccpaConsentState.consented); [expectation fulfill]; }); @@ -359,7 +358,7 @@ - (void)testOptionsConsentStateInitialSet { MPConsentState *storedConsentState = [[MPConsentState alloc] init]; [storedConsentState setCCPAConsentState:ccpaConsent]; [storedConsentState setGDPRConsentState:[MParticle sharedInstance].identity.currentUser.consentState.gdprConsentState]; - [MPPersistenceController setConsentState:storedConsentState forMpid:[MPPersistenceController mpId]]; + [MPPersistenceController_PRIVATE setConsentState:storedConsentState forMpid:[MPPersistenceController_PRIVATE mpId]]; XCTestExpectation *expectation = [self expectationWithDescription:@"async work"]; MParticle *instance = [MParticle sharedInstance]; @@ -379,7 +378,7 @@ - (void)testOptionsConsentStateInitialSet { options.consentState = newConsentState; [instance startWithOptions:options]; dispatch_async([MParticle messageQueue], ^{ - MPConsentState *storedConsentState = [MPPersistenceController consentStateForMpid:[MPPersistenceController mpId]]; + MPConsentState *storedConsentState = [MPPersistenceController_PRIVATE consentStateForMpid:[MPPersistenceController_PRIVATE mpId]]; XCTAssertFalse(storedConsentState.ccpaConsentState.consented); [expectation fulfill]; }); diff --git a/mParticle-Apple-SDK.xcodeproj/project.pbxproj b/mParticle-Apple-SDK.xcodeproj/project.pbxproj index c820d1fb4..721a18a6a 100644 --- a/mParticle-Apple-SDK.xcodeproj/project.pbxproj +++ b/mParticle-Apple-SDK.xcodeproj/project.pbxproj @@ -65,7 +65,7 @@ 534CD28929CE2CE1008452B3 /* MPKitRegisterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79CB629CE019F00E7489F /* MPKitRegisterTests.m */; }; 534CD28A29CE2CE1008452B3 /* MPStateMachineTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9129CE019F00E7489F /* MPStateMachineTests.m */; }; 534CD28B29CE2CE1008452B3 /* MPCCPAConsentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C8C29CE019F00E7489F /* MPCCPAConsentTests.m */; }; - 534CD28C29CE2CE1008452B3 /* MPIUserDefaultsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9929CE019F00E7489F /* MPIUserDefaultsTests.m */; }; + 534CD28C29CE2CE1008452B3 /* MPUserDefaultsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9929CE019F00E7489F /* MPUserDefaultsTests.m */; }; 534CD28D29CE2CE1008452B3 /* MPUploadBuilderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C8129CE019E00E7489F /* MPUploadBuilderTests.m */; }; 534CD28E29CE2CE1008452B3 /* MPBaseTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79CA229CE019F00E7489F /* MPBaseTestCase.m */; }; 534CD28F29CE2CE1008452B3 /* MPIdentityApiRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C7229CE019E00E7489F /* MPIdentityApiRequestTests.m */; }; @@ -126,7 +126,7 @@ 53A79B8329CDFB2000E7489F /* MPPersistenceController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AB829CDFB1E00E7489F /* MPPersistenceController.mm */; }; 53A79B8429CDFB2000E7489F /* MPDatabaseMigrationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AB929CDFB1E00E7489F /* MPDatabaseMigrationController.m */; }; 53A79B8529CDFB2000E7489F /* MPDatabaseMigrationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABA29CDFB1E00E7489F /* MPDatabaseMigrationController.h */; }; - 53A79B8629CDFB2000E7489F /* MPPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */; }; + 53A79B8629CDFB2000E7489F /* MPPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 53A79B8729CDFB2000E7489F /* MParticleUserNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABD29CDFB1E00E7489F /* MParticleUserNotification.h */; }; 53A79B8829CDFB2000E7489F /* MPDataModelAbstract.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABE29CDFB1E00E7489F /* MPDataModelAbstract.h */; }; 53A79B8929CDFB2000E7489F /* MPMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79ABF29CDFB1E00E7489F /* MPMessage.m */; }; @@ -157,13 +157,11 @@ 53A79BC629CDFB2000E7489F /* MParticleReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0029CDFB1F00E7489F /* MParticleReachability.h */; }; 53A79BC729CDFB2000E7489F /* MPMessageBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B0229CDFB1F00E7489F /* MPMessageBuilder.m */; }; 53A79BC829CDFB2000E7489F /* MPStateMachine.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B0329CDFB1F00E7489F /* MPStateMachine.m */; }; - 53A79BC929CDFB2000E7489F /* MPIUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0429CDFB1F00E7489F /* MPIUserDefaults.h */; }; 53A79BCE29CDFB2000E7489F /* NSDictionary+MPCaseInsensitive.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B0929CDFB1F00E7489F /* NSDictionary+MPCaseInsensitive.m */; }; 53A79BD229CDFB2000E7489F /* MPApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B0D29CDFB1F00E7489F /* MPApplication.m */; }; 53A79BD729CDFB2000E7489F /* MPUploadBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */; }; 53A79BDA29CDFB2000E7489F /* MPDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1529CDFB1F00E7489F /* MPDevice.m */; }; 53A79BDF29CDFB2000E7489F /* MPMessageBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */; }; - 53A79BE229CDFB2000E7489F /* MPIUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */; }; 53A79BE329CDFB2000E7489F /* MPBracket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */; }; 53A79BE829CDFB2000E7489F /* MPUploadBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */; }; 53A79BE929CDFB2000E7489F /* MPApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2429CDFB1F00E7489F /* MPApplication.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -283,7 +281,7 @@ 53A79CDE29CE019F00E7489F /* MPForwardQueueItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9529CE019F00E7489F /* MPForwardQueueItemTests.m */; }; 53A79CDF29CE019F00E7489F /* MPDateFormatterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9629CE019F00E7489F /* MPDateFormatterTests.m */; }; 53A79CE029CE019F00E7489F /* sample_dataplan2.json in Resources */ = {isa = PBXBuildFile; fileRef = 53A79C9829CE019F00E7489F /* sample_dataplan2.json */; }; - 53A79CE129CE019F00E7489F /* MPIUserDefaultsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9929CE019F00E7489F /* MPIUserDefaultsTests.m */; }; + 53A79CE129CE019F00E7489F /* MPUserDefaultsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9929CE019F00E7489F /* MPUserDefaultsTests.m */; }; 53A79CE229CE019F00E7489F /* MPLaunchInfoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9A29CE019F00E7489F /* MPLaunchInfoTests.m */; }; 53A79CE329CE019F00E7489F /* MPKitAppsFlyerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9C29CE019F00E7489F /* MPKitAppsFlyerTest.m */; }; 53A79CE429CE019F00E7489F /* MPConsentSerializationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79C9D29CE019F00E7489F /* MPConsentSerializationTests.m */; }; @@ -351,7 +349,6 @@ 53A79D3829CE23F700E7489F /* MPForwardQueueParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B5929CDFB1F00E7489F /* MPForwardQueueParameters.h */; }; 53A79D3929CE23F700E7489F /* MPIdentityApiManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79A9E29CDFB1E00E7489F /* MPIdentityApiManager.h */; }; 53A79D3A29CE23F700E7489F /* MPBaseProjection.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B6129CDFB1F00E7489F /* MPBaseProjection.h */; }; - 53A79D3B29CE23F700E7489F /* MPIUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0429CDFB1F00E7489F /* MPIUserDefaults.h */; }; 53A79D3C29CE23F700E7489F /* MPEventProjection.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B5629CDFB1F00E7489F /* MPEventProjection.h */; }; 53A79D3D29CE23F700E7489F /* MPUpload.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AC029CDFB1E00E7489F /* MPUpload.h */; }; 53A79D3F29CE23F700E7489F /* MPConsumerInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ACE29CDFB1F00E7489F /* MPConsumerInfo.h */; }; @@ -372,7 +369,7 @@ 53A79D5029CE23F700E7489F /* MPBracket.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2C29CDFB1F00E7489F /* MPBracket.h */; }; 53A79D5129CE23F700E7489F /* MParticleReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0029CDFB1F00E7489F /* MParticleReachability.h */; }; 53A79D5329CE23F700E7489F /* MPCustomModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B3029CDFB1F00E7489F /* MPCustomModule.h */; }; - 53A79D5529CE23F700E7489F /* MPPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */; }; + 53A79D5529CE23F700E7489F /* MPPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 53A79D5829CE23F700E7489F /* MPIdentityDTO.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA029CDFB1E00E7489F /* MPIdentityDTO.h */; }; 53A79D5929CE23F700E7489F /* MPMessageBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */; }; 53A79D5A29CE23F700E7489F /* MPURLRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA829CDFB1E00E7489F /* MPURLRequestBuilder.h */; }; @@ -414,7 +411,6 @@ 53A79D8829CE23F700E7489F /* MPApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B0D29CDFB1F00E7489F /* MPApplication.m */; }; 53A79D8A29CE23F700E7489F /* MPCustomModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B3229CDFB1F00E7489F /* MPCustomModule.m */; }; 53A79D8C29CE23F700E7489F /* MPKitActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B5529CDFB1F00E7489F /* MPKitActivity.m */; }; - 53A79D8E29CE23F700E7489F /* MPIUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */; }; 53A79D9029CE23F700E7489F /* MPDatabaseMigrationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AB929CDFB1E00E7489F /* MPDatabaseMigrationController.m */; }; 53A79D9129CE23F700E7489F /* MPConsentKitFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AF829CDFB1F00E7489F /* MPConsentKitFilter.m */; }; 53A79D9229CE23F700E7489F /* MPKitRegister.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B4C29CDFB1F00E7489F /* MPKitRegister.m */; }; @@ -463,6 +459,10 @@ 53FDD1BD2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; }; 53FDD1BE2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; }; D30CD0CB2CFF5FB100F5148A /* MPStateMachine.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0629CDFB1F00E7489F /* MPStateMachine.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D34286092D3806E600FEC2C8 /* MPUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34286082D3806CF00FEC2C8 /* MPUserDefaults.swift */; }; + D342860A2D3806E600FEC2C8 /* MPUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34286082D3806CF00FEC2C8 /* MPUserDefaults.swift */; }; + D342860F2D419CB800FEC2C8 /* MPUploadSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D342860E2D419CA700FEC2C8 /* MPUploadSettings.swift */; }; + D34286102D419CB800FEC2C8 /* MPUploadSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D342860E2D419CA700FEC2C8 /* MPUploadSettings.swift */; }; D346D8DB2D14682000FBA8B1 /* MPLaunchInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */; }; D346D8DC2D14682000FBA8B1 /* MPLaunchInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */; }; D342860C2D416C4E00FEC2C8 /* MPListenerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D342860B2D416C3E00FEC2C8 /* MPListenerProtocol.swift */; }; @@ -589,14 +589,12 @@ 53A79B0029CDFB1F00E7489F /* MParticleReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MParticleReachability.h; sourceTree = ""; }; 53A79B0229CDFB1F00E7489F /* MPMessageBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPMessageBuilder.m; sourceTree = ""; }; 53A79B0329CDFB1F00E7489F /* MPStateMachine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPStateMachine.m; sourceTree = ""; }; - 53A79B0429CDFB1F00E7489F /* MPIUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPIUserDefaults.h; sourceTree = ""; }; 53A79B0629CDFB1F00E7489F /* MPStateMachine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPStateMachine.h; sourceTree = ""; }; 53A79B0929CDFB1F00E7489F /* NSDictionary+MPCaseInsensitive.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+MPCaseInsensitive.m"; sourceTree = ""; }; 53A79B0D29CDFB1F00E7489F /* MPApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPApplication.m; sourceTree = ""; }; 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPUploadBuilder.m; sourceTree = ""; }; 53A79B1529CDFB1F00E7489F /* MPDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDevice.m; sourceTree = ""; }; 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPMessageBuilder.h; sourceTree = ""; }; - 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIUserDefaults.m; sourceTree = ""; }; 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MPBracket.cpp; sourceTree = ""; }; 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPUploadBuilder.h; sourceTree = ""; }; 53A79B2429CDFB1F00E7489F /* MPApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPApplication.h; sourceTree = ""; }; @@ -721,7 +719,7 @@ 53A79C9529CE019F00E7489F /* MPForwardQueueItemTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPForwardQueueItemTests.m; sourceTree = ""; }; 53A79C9629CE019F00E7489F /* MPDateFormatterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDateFormatterTests.m; sourceTree = ""; }; 53A79C9829CE019F00E7489F /* sample_dataplan2.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = sample_dataplan2.json; sourceTree = ""; }; - 53A79C9929CE019F00E7489F /* MPIUserDefaultsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIUserDefaultsTests.m; sourceTree = ""; }; + 53A79C9929CE019F00E7489F /* MPUserDefaultsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPUserDefaultsTests.m; sourceTree = ""; }; 53A79C9A29CE019F00E7489F /* MPLaunchInfoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPLaunchInfoTests.m; sourceTree = ""; }; 53A79C9B29CE019F00E7489F /* MPKitTestClassSideloaded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPKitTestClassSideloaded.h; sourceTree = ""; }; 53A79C9C29CE019F00E7489F /* MPKitAppsFlyerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPKitAppsFlyerTest.m; sourceTree = ""; }; @@ -758,6 +756,8 @@ 53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPSideloadedKit.swift; sourceTree = ""; }; 53E20DC62CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSArray+MPCaseInsensitiveTests.swift"; sourceTree = ""; }; 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIHasher.swift; sourceTree = ""; }; + D34286082D3806CF00FEC2C8 /* MPUserDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPUserDefaults.swift; sourceTree = ""; }; + D342860E2D419CA700FEC2C8 /* MPUploadSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPUploadSettings.swift; sourceTree = ""; }; D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPLaunchInfo.swift; sourceTree = ""; }; D342860B2D416C3E00FEC2C8 /* MPListenerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPListenerProtocol.swift; sourceTree = ""; }; D346D8D72D1069A600FBA8B1 /* MPListenerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPListenerController.swift; sourceTree = ""; }; @@ -924,7 +924,6 @@ 53A79AB829CDFB1E00E7489F /* MPPersistenceController.mm */, 53A79AB929CDFB1E00E7489F /* MPDatabaseMigrationController.m */, 53A79ABA29CDFB1E00E7489F /* MPDatabaseMigrationController.h */, - 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */, 531BCF322B28A23400F5C573 /* MPIdentityCaching.h */, 531BCF332B28A23400F5C573 /* MPIdentityCaching.m */, ); @@ -991,10 +990,11 @@ isa = PBXGroup; children = ( 534C11B22D08A73100466F71 /* MParticleWebView.swift */, + D34286082D3806CF00FEC2C8 /* MPUserDefaults.swift */, + D342860E2D419CA700FEC2C8 /* MPUploadSettings.swift */, 5399DDB72CA727E1006526E1 /* MPZip.swift */, 53A79B0229CDFB1F00E7489F /* MPMessageBuilder.m */, D3961CD52CB468DC003B3194 /* NSArray+MPCaseInsensitive.swift */, - 53A79B0429CDFB1F00E7489F /* MPIUserDefaults.h */, D3CEDACA2CB027E1001B32DF /* MPConvertJS.swift */, 53A79B0929CDFB1F00E7489F /* NSDictionary+MPCaseInsensitive.m */, D356E0232CFE08ED0020898D /* MPResponseConfig.swift */, @@ -1005,7 +1005,6 @@ 53A79B1529CDFB1F00E7489F /* MPDevice.m */, D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */, 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */, - 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */, 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */, 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */, 53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */, @@ -1157,6 +1156,7 @@ 53A79B2429CDFB1F00E7489F /* MPApplication.h */, 53A79B3429CDFB1F00E7489F /* MPNotificationController.h */, 53A79AA329CDFB1E00E7489F /* MPBackendController.h */, + 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */, ); path = Include; sourceTree = ""; @@ -1212,7 +1212,7 @@ 53A79C9429CE019F00E7489F /* MPKitSecondTestClass.h */, 53A79C9529CE019F00E7489F /* MPForwardQueueItemTests.m */, 53A79C9629CE019F00E7489F /* MPDateFormatterTests.m */, - 53A79C9929CE019F00E7489F /* MPIUserDefaultsTests.m */, + 53A79C9929CE019F00E7489F /* MPUserDefaultsTests.m */, 53A79C9A29CE019F00E7489F /* MPLaunchInfoTests.m */, 53A79C9B29CE019F00E7489F /* MPKitTestClassSideloaded.h */, 53A79C9C29CE019F00E7489F /* MPKitAppsFlyerTest.m */, @@ -1321,7 +1321,6 @@ 53A79C1729CDFB2100E7489F /* MPForwardQueueParameters.h in Headers */, 53A79B6C29CDFB2000E7489F /* MPIdentityApiManager.h in Headers */, 53A79C1F29CDFB2100E7489F /* MPBaseProjection.h in Headers */, - 53A79BC929CDFB2000E7489F /* MPIUserDefaults.h in Headers */, 53A79C1429CDFB2100E7489F /* MPEventProjection.h in Headers */, 534CD25E29CE2BF1008452B3 /* MParticleSwift.h in Headers */, 53A79B8A29CDFB2000E7489F /* MPUpload.h in Headers */, @@ -1409,7 +1408,6 @@ 53A79D3829CE23F700E7489F /* MPForwardQueueParameters.h in Headers */, 53A79D3929CE23F700E7489F /* MPIdentityApiManager.h in Headers */, 53A79D3A29CE23F700E7489F /* MPBaseProjection.h in Headers */, - 53A79D3B29CE23F700E7489F /* MPIUserDefaults.h in Headers */, 53A79D3C29CE23F700E7489F /* MPEventProjection.h in Headers */, 534CD25F29CE2BF1008452B3 /* MParticleSwift.h in Headers */, 53A79D3D29CE23F700E7489F /* MPUpload.h in Headers */, @@ -1648,7 +1646,7 @@ 534CD28929CE2CE1008452B3 /* MPKitRegisterTests.m in Sources */, 534CD28A29CE2CE1008452B3 /* MPStateMachineTests.m in Sources */, 534CD28B29CE2CE1008452B3 /* MPCCPAConsentTests.m in Sources */, - 534CD28C29CE2CE1008452B3 /* MPIUserDefaultsTests.m in Sources */, + 534CD28C29CE2CE1008452B3 /* MPUserDefaultsTests.m in Sources */, 534CD28D29CE2CE1008452B3 /* MPUploadBuilderTests.m in Sources */, 534CD28E29CE2CE1008452B3 /* MPBaseTestCase.m in Sources */, 534CD28F29CE2CE1008452B3 /* MPIdentityApiRequestTests.m in Sources */, @@ -1717,7 +1715,7 @@ 53A79BD229CDFB2000E7489F /* MPApplication.m in Sources */, 53A79BF629CDFB2000E7489F /* MPCustomModule.m in Sources */, 53A79C1329CDFB2100E7489F /* MPKitActivity.m in Sources */, - 53A79BE229CDFB2000E7489F /* MPIUserDefaults.m in Sources */, + D34286092D3806E600FEC2C8 /* MPUserDefaults.swift in Sources */, 53A79B8429CDFB2000E7489F /* MPDatabaseMigrationController.m in Sources */, 53A79BC029CDFB2000E7489F /* MPConsentKitFilter.m in Sources */, 53A79C0A29CDFB2100E7489F /* MPKitRegister.m in Sources */, @@ -1753,6 +1751,7 @@ 53A79C0829CDFB2100E7489F /* MPEvent.m in Sources */, 53A79B6729CDFB2000E7489F /* MPAliasResponse.m in Sources */, 534C11B72D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */, + D342860F2D419CB800FEC2C8 /* MPUploadSettings.swift in Sources */, 53A79C1229CDFB2100E7489F /* MPKitFilter.m in Sources */, D342860C2D416C4E00FEC2C8 /* MPListenerProtocol.swift in Sources */, 53A79B7829CDFB2000E7489F /* MPURLConnectionAssociate.m in Sources */, @@ -1820,7 +1819,7 @@ 53A79CF829CE019F00E7489F /* MPKitRegisterTests.m in Sources */, 53A79CDB29CE019F00E7489F /* MPStateMachineTests.m in Sources */, 53A79CD629CE019F00E7489F /* MPCCPAConsentTests.m in Sources */, - 53A79CE129CE019F00E7489F /* MPIUserDefaultsTests.m in Sources */, + 53A79CE129CE019F00E7489F /* MPUserDefaultsTests.m in Sources */, 53A79CCD29CE019F00E7489F /* MPUploadBuilderTests.m in Sources */, 53A79CE829CE019F00E7489F /* MPBaseTestCase.m in Sources */, 53A79CC029CE019F00E7489F /* MPIdentityApiRequestTests.m in Sources */, @@ -1888,7 +1887,7 @@ 53A79D8829CE23F700E7489F /* MPApplication.m in Sources */, 53A79D8A29CE23F700E7489F /* MPCustomModule.m in Sources */, 53A79D8C29CE23F700E7489F /* MPKitActivity.m in Sources */, - 53A79D8E29CE23F700E7489F /* MPIUserDefaults.m in Sources */, + D342860A2D3806E600FEC2C8 /* MPUserDefaults.swift in Sources */, D3CEDAC42C9DB0E0001B32DF /* MPDateFormatter.swift in Sources */, 53A79D9029CE23F700E7489F /* MPDatabaseMigrationController.m in Sources */, 53A79D9129CE23F700E7489F /* MPConsentKitFilter.m in Sources */, @@ -1924,6 +1923,7 @@ 53A79DAA29CE23F700E7489F /* MPNotificationController.m in Sources */, 53A79DAB29CE23F700E7489F /* MPEvent.m in Sources */, 534C11B62D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */, + D34286102D419CB800FEC2C8 /* MPUploadSettings.swift in Sources */, 53A79DAD29CE23F700E7489F /* MPAliasResponse.m in Sources */, D342860D2D416C4E00FEC2C8 /* MPListenerProtocol.swift in Sources */, 53A79DAE29CE23F700E7489F /* MPKitFilter.m in Sources */, diff --git a/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m b/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m index 553024dae..4520eabbd 100644 --- a/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m +++ b/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m @@ -22,7 +22,7 @@ @interface MParticle () @property (nonatomic, strong, readonly) MPBackendController_PRIVATE *backendController; -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; + (dispatch_queue_t)messageQueue; diff --git a/mParticle-Apple-SDK/Custom Modules/MPCustomModulePreference.m b/mParticle-Apple-SDK/Custom Modules/MPCustomModulePreference.m index 4622468ac..09fe2ccb6 100644 --- a/mParticle-Apple-SDK/Custom Modules/MPCustomModulePreference.m +++ b/mParticle-Apple-SDK/Custom Modules/MPCustomModulePreference.m @@ -1,10 +1,16 @@ #import "MPCustomModulePreference.h" -#import "MPIUserDefaults.h" #import "MPILogger.h" #import "MParticleSwift.h" #import "MPPersistenceController.h" #import "mParticle.h" +@interface MParticle () + +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; + +@end + @interface MPCustomModulePreference() @property (nonatomic, strong) NSString *location; @@ -168,11 +174,11 @@ - (NSString *)uuidWithNoDashes { #pragma mark Public methods - (id)value { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSString *deprecatedKey = [NSString stringWithFormat:@"cms::%@", self.writeKey]; NSString *customModuleKey = [NSString stringWithFormat:@"cms::%@::%@", self.moduleId, self.writeKey]; - NSNumber *mpId = [MPPersistenceController mpId]; + NSNumber *mpId = [MPPersistenceController_PRIVATE mpId]; id valueWithDeprecatedKey = [userDefaults mpObjectForKey:deprecatedKey userId:mpId]; if (valueWithDeprecatedKey) { _value = valueWithDeprecatedKey; diff --git a/mParticle-Apple-SDK/Data Model/MPConsumerInfo.m b/mParticle-Apple-SDK/Data Model/MPConsumerInfo.m index d41fdbda1..724a80e85 100644 --- a/mParticle-Apple-SDK/Data Model/MPConsumerInfo.m +++ b/mParticle-Apple-SDK/Data Model/MPConsumerInfo.m @@ -1,7 +1,6 @@ #import "MPConsumerInfo.h" #import "MPIConstants.h" #import "MPILogger.h" -#import "MPIUserDefaults.h" #import "MParticleSwift.h" #import "MPPersistenceController.h" #import "mParticle.h" @@ -12,7 +11,9 @@ @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @end @@ -196,10 +197,10 @@ - (void)configureCookiesWithDictionary:(NSDictionary *)cookiesDictionary { return; } - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSMutableArray *cookies = [[NSMutableArray alloc] init]; - NSArray *fetchedCookies = [persistence fetchCookiesForUserId:[MPPersistenceController mpId]]; + NSArray *fetchedCookies = [persistence fetchCookiesForUserId:[MPPersistenceController_PRIVATE mpId]]; if (fetchedCookies) { [cookies addObjectsFromArray:fetchedCookies]; } @@ -238,8 +239,8 @@ - (void)configureCookiesWithDictionary:(NSDictionary *)cookiesDictionary { } - (NSDictionary *)localCookiesDictionary { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSDictionary *localCookies = [userDefaults mpObjectForKey:kMPRemoteConfigCookiesKey userId:[MPPersistenceController mpId]]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; + NSDictionary *localCookies = [userDefaults mpObjectForKey:kMPRemoteConfigCookiesKey userId:[MPPersistenceController_PRIVATE mpId]]; if (!localCookies) { return nil; @@ -264,7 +265,7 @@ - (NSString *)uniqueIdentifier { return _uniqueIdentifier; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (userDefaults[kMPRemoteConfigUniqueIdentifierKey]) { _uniqueIdentifier = userDefaults[kMPRemoteConfigUniqueIdentifierKey]; [userDefaults removeMPObjectForKey:kMPRemoteConfigUniqueIdentifierKey]; @@ -288,7 +289,7 @@ - (void)setUniqueIdentifier:(NSString *)uniqueIdentifier { - (NSString *)deviceApplicationStamp { __block NSString *value = nil; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; value = userDefaults[kMPDeviceApplicationStampStorageKey]; if (!value) { diff --git a/mParticle-Apple-SDK/Data Model/MPForwardRecord.m b/mParticle-Apple-SDK/Data Model/MPForwardRecord.m index ea5dc2b15..98b77e8f8 100644 --- a/mParticle-Apple-SDK/Data Model/MPForwardRecord.m +++ b/mParticle-Apple-SDK/Data Model/MPForwardRecord.m @@ -83,7 +83,7 @@ - (instancetype)initWithMessageType:(MPMessageType)messageType execStatus:(MPKit } _forwardRecordId = 0; - _mpid = [MPPersistenceController mpId]; + _mpid = [MPPersistenceController_PRIVATE mpId]; _dataDictionary = [[NSMutableDictionary alloc] init]; _dataDictionary[kMPFRModuleId] = execStatus.integrationId; _dataDictionary[kMPTimestampKey] = MPCurrentEpochInMilliseconds; diff --git a/mParticle-Apple-SDK/Data Model/MPSession.m b/mParticle-Apple-SDK/Data Model/MPSession.m index 61e7c7aa7..b8ce8d475 100644 --- a/mParticle-Apple-SDK/Data Model/MPSession.m +++ b/mParticle-Apple-SDK/Data Model/MPSession.m @@ -10,7 +10,7 @@ @implementation MPSession - (instancetype)init { NSTimeInterval now = [[NSDate date] timeIntervalSince1970]; - NSNumber *mpId = [MPPersistenceController mpId]; + NSNumber *mpId = [MPPersistenceController_PRIVATE mpId]; return [self initWithSessionId:0 UUID:[[NSUUID UUID] UUIDString] backgroundTime:0.0 diff --git a/mParticle-Apple-SDK/Data Model/MPUpload.h b/mParticle-Apple-SDK/Data Model/MPUpload.h index a282df6d4..1a86d00e5 100644 --- a/mParticle-Apple-SDK/Data Model/MPUpload.h +++ b/mParticle-Apple-SDK/Data Model/MPUpload.h @@ -4,26 +4,7 @@ @class MPSession; @class MPNetworkOptions; - -// Upload credentials and options -@interface MPUploadSettings : NSObject -@property (nonatomic, strong, nonnull) NSString *apiKey; -@property (nonatomic, strong, nonnull) NSString *secret; -@property (nonatomic, strong, nullable) NSString *eventsHost; -@property (nonatomic, strong, nullable) NSString *eventsTrackingHost; -@property (nonatomic) BOOL overridesEventsSubdirectory; -@property (nonatomic, strong, nullable) NSString *aliasHost; -@property (nonatomic, strong, nullable) NSString *aliasTrackingHost; -@property (nonatomic) BOOL overridesAliasSubdirectory; -@property (nonatomic) BOOL eventsOnly; - -+ (nonnull MPUploadSettings *)currentUploadSettings; - -- (nonnull instancetype)initWithApiKey:(nonnull NSString *)apiKey secret:(nonnull NSString *)secret eventsHost:(nullable NSString *)eventsHost eventsTrackingHost:(nullable NSString *)eventsTrackingHost overridesEventsSubdirectory:(BOOL)overridesEventsSubdirectory aliasHost:(nullable NSString *)aliasHost aliasTrackingHost:(nullable NSString *)aliasTrackingHost overridesAliasSubdirectory:(BOOL)overridesAliasSubdirectory eventsOnly:(BOOL)eventsOnly; - -- (nonnull instancetype)initWithApiKey:(nonnull NSString *)apiKey secret:(nonnull NSString *)secret networkOptions:(nullable MPNetworkOptions *)networkOptions; - -@end +@class MPUploadSettings; @interface MPUpload : MPDataModelAbstract diff --git a/mParticle-Apple-SDK/Data Model/MPUpload.m b/mParticle-Apple-SDK/Data Model/MPUpload.m index 240b4c7ae..206e04945 100644 --- a/mParticle-Apple-SDK/Data Model/MPUpload.m +++ b/mParticle-Apple-SDK/Data Model/MPUpload.m @@ -2,103 +2,12 @@ #import "MPSession.h" #import "MPIConstants.h" #import "mParticle.h" +#import "MParticleSwift.h" @interface MParticle() @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @end -@implementation MPUploadSettings - -+ (MPUploadSettings *)currentUploadSettings { - MParticle *mParticle = [MParticle sharedInstance]; - MPUploadSettings *uploadSettings = [[MPUploadSettings alloc] initWithApiKey:mParticle.stateMachine.apiKey - secret:mParticle.stateMachine.secret - networkOptions:mParticle.networkOptions]; - return uploadSettings; -} - -- (instancetype)initWithApiKey:(nonnull NSString *)apiKey secret:(nonnull NSString *)secret eventsHost:(nullable NSString *)eventsHost eventsTrackingHost:(nullable NSString *)eventsTrackingHost overridesEventsSubdirectory:(BOOL)overridesEventsSubdirectory aliasHost:(nullable NSString *)aliasHost aliasTrackingHost:(nullable NSString *)aliasTrackingHost overridesAliasSubdirectory:(BOOL)overridesAliasSubdirectory eventsOnly:(BOOL)eventsOnly { - if (self = [super init]) { - _apiKey = apiKey; - _secret = secret; - _eventsHost = eventsHost; - _eventsTrackingHost = eventsTrackingHost; - _overridesEventsSubdirectory = overridesEventsSubdirectory; - _aliasHost = aliasHost; - _aliasTrackingHost = aliasTrackingHost; - _overridesAliasSubdirectory = overridesAliasSubdirectory; - _eventsOnly = eventsOnly; - } - return self; -} - -- (nonnull instancetype)initWithApiKey:(nonnull NSString *)apiKey secret:(nonnull NSString *)secret networkOptions:(MPNetworkOptions *)networkOptions { - return [self initWithApiKey:apiKey - secret:secret - eventsHost:networkOptions.eventsHost - eventsTrackingHost:networkOptions.eventsTrackingHost - overridesEventsSubdirectory:networkOptions.overridesEventsSubdirectory - aliasHost:networkOptions.aliasHost - aliasTrackingHost:networkOptions.aliasTrackingHost - overridesAliasSubdirectory:networkOptions.overridesAliasSubdirectory - eventsOnly:networkOptions.eventsOnly]; -} - -static NSString * const kApiKey = @"apiKey"; -static NSString * const kSecret = @"secret"; -static NSString * const kEventsHost = @"eventsHost"; -static NSString * const kEventsTrackingHost = @"eventsTrackingHost"; -static NSString * const kOverridesEventsSubdirectory = @"overridesEventsSubdirectory"; -static NSString * const kAliasHost = @"aliasHost"; -static NSString * const kAliasTrackingHost = @"aliasTrackingHost"; -static NSString * const kOverridesAliasSubdirectory = @"overridesAliasSubdirectory"; -static NSString * const kEventsOnly = @"eventsOnly"; - -- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder { - if (self = [super init]) { - _apiKey = [coder decodeObjectForKey:kApiKey]; - _secret = [coder decodeObjectForKey:kSecret]; - _eventsHost = [coder decodeObjectForKey:kEventsHost]; - _eventsTrackingHost = [coder decodeObjectForKey:kEventsTrackingHost]; - _overridesEventsSubdirectory = [coder decodeBoolForKey:kOverridesEventsSubdirectory]; - _aliasHost = [coder decodeObjectForKey:kAliasHost]; - _aliasTrackingHost = [coder decodeObjectForKey:kAliasTrackingHost]; - _overridesAliasSubdirectory = [coder decodeBoolForKey:kOverridesAliasSubdirectory]; - _eventsOnly = [coder decodeBoolForKey:kEventsOnly]; - } - return self; -} - -- (void)encodeWithCoder:(nonnull NSCoder *)coder { - [coder encodeObject:_apiKey forKey:kApiKey]; - [coder encodeObject:_secret forKey:kSecret]; - [coder encodeObject:_eventsHost forKey:kEventsHost]; - [coder encodeObject:_eventsTrackingHost forKey:kEventsTrackingHost]; - [coder encodeBool:_overridesEventsSubdirectory forKey:kOverridesEventsSubdirectory]; - [coder encodeObject:_aliasHost forKey:kAliasHost]; - [coder encodeObject:_aliasTrackingHost forKey:kAliasTrackingHost]; - [coder encodeBool:_overridesAliasSubdirectory forKey:kOverridesAliasSubdirectory]; - [coder encodeBool:_eventsOnly forKey:kEventsOnly]; -} - -+ (BOOL)supportsSecureCoding { - return YES; -} - -- (id)copyWithZone:(NSZone *)zone { - return [[MPUploadSettings alloc] initWithApiKey:_apiKey - secret:_secret - eventsHost:_eventsHost - eventsTrackingHost:_eventsTrackingHost - overridesEventsSubdirectory:_overridesEventsSubdirectory - aliasHost:_aliasHost - aliasTrackingHost:_aliasTrackingHost - overridesAliasSubdirectory:_overridesAliasSubdirectory - eventsOnly:_eventsOnly]; -} - -@end - @implementation MPUpload - (instancetype)initWithSessionId:(NSNumber *)sessionId uploadDictionary:(NSDictionary *)uploadDictionary dataPlanId:(nullable NSString *)dataPlanId dataPlanVersion:(nullable NSNumber *)dataPlanVersion uploadSettings:(nonnull MPUploadSettings *)uploadSettings { diff --git a/mParticle-Apple-SDK/Identity/MPIdentityApi.m b/mParticle-Apple-SDK/Identity/MPIdentityApi.m index 36a41a00f..d0041f24b 100644 --- a/mParticle-Apple-SDK/Identity/MPIdentityApi.m +++ b/mParticle-Apple-SDK/Identity/MPIdentityApi.m @@ -7,7 +7,6 @@ #import "mParticle.h" #import "MPBackendController.h" #import "MPConsumerInfo.h" -#import "MPIUserDefaults.h" #import "MPSession.h" #import "MPPersistenceController.h" #import "MPIdentityDTO.h" @@ -16,6 +15,7 @@ #import "MPKitContainer.h" #import "MPDevice.h" #import "MPUpload.h" +#import "MParticleSwift.h" typedef NS_ENUM(NSUInteger, MPIdentityRequestType) { MPIdentityRequestIdentify = 0, @@ -26,7 +26,7 @@ typedef NS_ENUM(NSUInteger, MPIdentityRequestType) { @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @end @@ -154,8 +154,8 @@ - (void)onIdentityRequestComplete:(MPIdentityApiRequest *)request identityReques } return; } - NSNumber *previousMPID = [MPPersistenceController mpId]; - [MPPersistenceController setMpid:httpResponse.mpid]; + NSNumber *previousMPID = [MPPersistenceController_PRIVATE mpId]; + [MPPersistenceController_PRIVATE setMpid:httpResponse.mpid]; MPIdentityApiResult *apiResult = [[MPIdentityApiResult alloc] init]; MParticleUser *previousUser = self.currentUser; MParticleUser *user = [[MParticleUser alloc] init]; @@ -169,7 +169,7 @@ - (void)onIdentityRequestComplete:(MPIdentityApiRequest *)request identityReques NSString *userIdsString = session.sessionUserIds; NSMutableArray *userIds = [[userIdsString componentsSeparatedByString:@","] mutableCopy]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (user.userId.longLongValue != 0) { [userDefaults setMPObject:[NSDate date] forKey:kMPLastIdentifiedDate userId:user.userId]; @@ -216,7 +216,7 @@ - (void)onIdentityRequestComplete:(MPIdentityApiRequest *)request identityReques - (void)onMPIDChange:(MPIdentityApiRequest *)request httpResponse:(MPIdentityHTTPSuccessResponse *)httpResponse previousUser:(MParticleUser *)previousUser newUser:(MParticleUser *)newUser { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSDate *date = [NSDate date]; NSNumber *dateMs = @([date timeIntervalSince1970] * 1000.0); @@ -304,7 +304,7 @@ - (MParticleUser *)currentUser { return _currentUser; } - NSNumber *mpid = [MPPersistenceController mpId]; + NSNumber *mpid = [MPPersistenceController_PRIVATE mpId]; MParticleUser *user = [[MParticleUser alloc] init]; user.userId = mpid; _currentUser = user; @@ -312,7 +312,7 @@ - (MParticleUser *)currentUser { } - (MParticleUser *)getUser:(NSNumber *)mpId { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if ([userDefaults isExistingUserId:mpId]) { MParticleUser *user = [[MParticleUser alloc] init]; user.userId = mpId; @@ -343,7 +343,7 @@ - (MParticleUser *)getUser:(NSNumber *)mpId { } - (NSArray *)getAllUsers { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSMutableArray *userArray = [[NSMutableArray alloc] init]; for (NSNumber *userID in [userDefaults userIDsInUserDefaults]) { @@ -485,7 +485,7 @@ - (BOOL)aliasUsers:(MPAliasRequest *)aliasRequest { uploadType:MPUploadTypeAlias dataPlanId:[MParticle sharedInstance].dataPlanId dataPlanVersion:[MParticle sharedInstance].dataPlanVersion - uploadSettings:[MPUploadSettings currentUploadSettings]]; + uploadSettings:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; [MParticle.sharedInstance.persistenceController saveUpload:upload]; [MParticle.sharedInstance.backendController waitForKitsAndUploadWithCompletionHandler:nil]; diff --git a/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m b/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m index 55f8049d0..b4e4ed1b2 100644 --- a/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m +++ b/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m @@ -7,7 +7,6 @@ #import "MPNotificationController.h" #import "MPIConstants.h" #import "MPStateMachine.h" -#import "MPIUserDefaults.h" #import "MPIdentityDTO.h" @interface MPIdentityApiRequest () diff --git a/mParticle-Apple-SDK/Identity/MPIdentityDTO.m b/mParticle-Apple-SDK/Identity/MPIdentityDTO.m index 4a2f91d01..b64aafbb2 100644 --- a/mParticle-Apple-SDK/Identity/MPIdentityDTO.m +++ b/mParticle-Apple-SDK/Identity/MPIdentityDTO.m @@ -8,11 +8,11 @@ #import "MPNotificationController.h" #import "MPPersistenceController.h" #import "MPConsumerInfo.h" -#import "MPIUserDefaults.h" +#import "mParticleSwift.h" @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @end @@ -54,9 +54,9 @@ - (instancetype)initWithIdentityApiRequest:(MPIdentityApiRequest *)apiRequest { if (self) { _knownIdentities = [[MPIdentityHTTPIdentities alloc] initWithIdentities:apiRequest.identities]; - NSNumber *mpid = [MPPersistenceController mpId]; + NSNumber *mpid = [MPPersistenceController_PRIVATE mpId]; if (mpid.longLongValue != 0) { - _previousMPID = [MPPersistenceController mpId].stringValue; + _previousMPID = [MPPersistenceController_PRIVATE mpId].stringValue; } MPDevice *device = [[MPDevice alloc] init]; @@ -75,7 +75,7 @@ - (instancetype)initWithIdentityApiRequest:(MPIdentityApiRequest *)apiRequest { if (![MPStateMachine_PRIVATE isAppExtension]) { NSData *deviceTokenData = [MPNotificationController_PRIVATE deviceToken]; if (deviceTokenData) { - NSString *deviceTokenString = [MPIUserDefaults stringFromDeviceToken:deviceTokenData]; + NSString *deviceTokenString = [MPUserDefaults stringFromDeviceToken:deviceTokenData]; if (deviceTokenString && [deviceTokenString length] > 0) { _knownIdentities.pushToken = deviceTokenString; } diff --git a/mParticle-Apple-SDK/Identity/MParticleUser.m b/mParticle-Apple-SDK/Identity/MParticleUser.m index 718072723..6efc866ac 100644 --- a/mParticle-Apple-SDK/Identity/MParticleUser.m +++ b/mParticle-Apple-SDK/Identity/MParticleUser.m @@ -6,11 +6,10 @@ #import "MPILogger.h" #import "mParticle.h" #import "MPPersistenceController.h" -#import "MPIUserDefaults.h" #import "MPDataPlanFilter.h" #import "MPIConstants.h" #import "MPKitContainer.h" -#import "MParticleSwift.h" +#import "mParticleSwift.h" @interface MParticleUser () @@ -22,7 +21,7 @@ @interface MParticle () + (dispatch_queue_t)messageQueue; @property (nonatomic, strong) MPBackendController_PRIVATE *backendController; -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong) MPDataPlanFilter *dataPlanFilter; @@ -47,7 +46,7 @@ - (instancetype)init } - (NSDate *)firstSeen { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSNumber *firstSeenMs = [userDefaults mpObjectForKey:kMPFirstSeenUser userId:self.userId]; return [NSDate dateWithTimeIntervalSince1970:firstSeenMs.doubleValue/1000.0]; } @@ -56,13 +55,13 @@ - (NSDate *)lastSeen { if ([MParticle.sharedInstance.identity.currentUser.userId isEqual:self.userId]) { return [NSDate date]; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSNumber *lastSeenMs = [userDefaults mpObjectForKey:kMPLastSeenUser userId:self.userId]; return [NSDate dateWithTimeIntervalSince1970:lastSeenMs.doubleValue/1000.0]; } - (NSDictionary*) identities { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSArray *userIdentityArray = [userDefaults mpObjectForKey:kMPUserIdentityArrayKey userId:_userId]; NSMutableDictionary *userIdentities = [NSMutableDictionary dictionary]; @@ -160,8 +159,8 @@ - (void)setIdentitySync:(NSString *)identityString identityType:(MPIdentity)iden return foundMatch; }; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSMutableArray *identities = [[userDefaults mpObjectForKey:kMPUserIdentityArrayKey userId:[MPPersistenceController mpId]] mutableCopy]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; + NSMutableArray *identities = [[userDefaults mpObjectForKey:kMPUserIdentityArrayKey userId:[MPPersistenceController_PRIVATE mpId]] mutableCopy]; if (!identities) { identities = [[NSMutableArray alloc] init]; } @@ -450,7 +449,7 @@ - (void)removeUserAttribute:(nonnull NSString *)key { - (void)setConsentState:(MPConsentState *)state { - [MPPersistenceController setConsentState:state forMpid:self.userId]; + [MPPersistenceController_PRIVATE setConsentState:state forMpid:self.userId]; NSArray *kitConfig = [[MParticle sharedInstance].kitContainer_PRIVATE.originalConfig copy]; if (kitConfig) { @@ -470,7 +469,7 @@ - (void)setConsentState:(MPConsentState *)state { } - (nullable MPConsentState *)consentState { - return [MPPersistenceController consentStateForMpid:self.userId]; + return [MPPersistenceController_PRIVATE consentStateForMpid:self.userId]; } diff --git a/mParticle-Apple-SDK/Persistence/MPPersistenceController.h b/mParticle-Apple-SDK/Include/MPPersistenceController.h similarity index 97% rename from mParticle-Apple-SDK/Persistence/MPPersistenceController.h rename to mParticle-Apple-SDK/Include/MPPersistenceController.h index 553b16adb..583b8a27e 100644 --- a/mParticle-Apple-SDK/Persistence/MPPersistenceController.h +++ b/mParticle-Apple-SDK/Include/MPPersistenceController.h @@ -1,5 +1,4 @@ #import -#import "MParticleUserNotification.h" @class MPMessage; @class MPSession; @@ -15,7 +14,7 @@ @class MParticleUserNotification; #endif -@interface MPPersistenceController : NSObject +@interface MPPersistenceController_PRIVATE : NSObject @property (nonatomic, readonly, getter = isDatabaseOpen) BOOL databaseOpen; diff --git a/mParticle-Apple-SDK/Include/mParticle.h b/mParticle-Apple-SDK/Include/mParticle.h index dc59cb194..80576fe86 100644 --- a/mParticle-Apple-SDK/Include/mParticle.h +++ b/mParticle-Apple-SDK/Include/mParticle.h @@ -24,6 +24,7 @@ #import "MPApplication.h" #import "MPNotificationController.h" #import "MPNetworkCommunication.h" +#import "MPPersistenceController.h" #if TARGET_OS_IOS == 1 #ifndef MPARTICLE_LOCATION_DISABLE @@ -91,7 +92,7 @@ NS_ASSUME_NONNULL_BEGIN /** Allows you to override the default configuration host. */ -@property (nonatomic) NSString *configHost; +@property (nonatomic, nullable) NSString *configHost; /** Defaults to false. If set true the configHost above with overwrite the subdirectory of the URL in addition to the host. */ @@ -100,11 +101,11 @@ Defaults to false. If set true the configHost above with overwrite the subdirect /** Allows you to override the default event host. */ -@property (nonatomic) NSString *eventsHost; +@property (nonatomic, nullable) NSString *eventsHost; /** Allows you to override the tracking event host. Set this to automatically use an alternate custom domain when ATTStatus has been authorized. */ -@property (nonatomic) NSString *eventsTrackingHost; +@property (nonatomic, nullable) NSString *eventsTrackingHost; /** Defaults to false. If set true the eventsHost above with overwrite the subdirectory of the URL in addition to the host. */ @@ -113,11 +114,11 @@ Defaults to false. If set true the eventsHost above with overwrite the subdirect /** Allows you to override the default identity host. */ -@property (nonatomic) NSString *identityHost; +@property (nonatomic, nullable) NSString *identityHost; /** Allows you to override the tracking identity host. Set this to automatically use an alternate custom domain when ATTStatus has been authorized. */ -@property (nonatomic) NSString *identityTrackingHost; +@property (nonatomic, nullable) NSString *identityTrackingHost; /** Defaults to false. If set true the identityHost above with overwrite the subdirectory of the URL in addition to the host. */ @@ -126,11 +127,11 @@ Defaults to false. If set true the identityHost above with overwrite the subdire /** Allows you to override the default alias host. */ -@property (nonatomic) NSString *aliasHost; +@property (nonatomic, nullable) NSString *aliasHost; /** Allows you to override the tracking alias host. Set this to automatically use an alternate custom domain when ATTStatus has been authorized. */ -@property (nonatomic) NSString *aliasTrackingHost; +@property (nonatomic, nullable) NSString *aliasTrackingHost; /** Defaults to false. If set true the aliasHost above with overwrite the subdirectory of the URL in addition to the host. */ @@ -1235,6 +1236,11 @@ Defaults to false. Prevents the eventsHost above from overwriting the alias endp */ + (void)_setWrapperSdk_internal:(MPWrapperSdk)wrapperSdk version:(nonnull NSString *)wrapperSdkVersion; +/** + Internal use only. Used by our SDK to determine if configuration needs refreshed. + */ ++ (BOOL)isOlderThanConfigMaxAgeSeconds; + @end NS_ASSUME_NONNULL_END diff --git a/mParticle-Apple-SDK/Kits/MPKitAPI.m b/mParticle-Apple-SDK/Kits/MPKitAPI.m index 658a0f877..937a528cf 100644 --- a/mParticle-Apple-SDK/Kits/MPKitAPI.m +++ b/mParticle-Apple-SDK/Kits/MPKitAPI.m @@ -8,7 +8,7 @@ @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @end diff --git a/mParticle-Apple-SDK/Kits/MPKitContainer.mm b/mParticle-Apple-SDK/Kits/MPKitContainer.mm index af2ba6896..b8fbe9d83 100644 --- a/mParticle-Apple-SDK/Kits/MPKitContainer.mm +++ b/mParticle-Apple-SDK/Kits/MPKitContainer.mm @@ -18,7 +18,6 @@ #import "MPProduct.h" #import "MPProduct+Dictionary.h" #import "NSDictionary+MPCaseInsensitive.h" -#import "MPIUserDefaults.h" #import "MPConsumerInfo.h" #import "MPForwardQueueItem.h" #import "MPTransactionAttributes.h" @@ -43,8 +42,9 @@ static NSMutableSet > *kitsRegistry; @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; + (dispatch_queue_t)messageQueue; @property (nonatomic, strong, nonnull) MParticleOptions *options; @property (nonatomic, strong) MPDataPlanFilter *dataPlanFilter; @@ -288,7 +288,7 @@ - (void)initializeKits { return; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSArray *directoryContents = [userDefaults getKitConfigurations]; @@ -411,7 +411,7 @@ - (BOOL)isDisabledByBracketConfiguration:(NSDictionary *)bracketConfiguration { NSString *const MPKitBracketLowKey = @"lo"; NSString *const MPKitBracketHighKey = @"hi"; - long mpId = [[MPPersistenceController mpId] longValue]; + long mpId = [[MPPersistenceController_PRIVATE mpId] longValue]; short low = (short)[bracketConfiguration[MPKitBracketLowKey] integerValue]; short high = (short)[bracketConfiguration[MPKitBracketHighKey] integerValue]; localBracket = make_shared(mpId, low, high); @@ -610,7 +610,7 @@ - (void)updateBracketsWithConfiguration:(NSDictionary *)configuration integratio return; } - long mpId = [[MPPersistenceController mpId] longValue]; + long mpId = [[MPPersistenceController_PRIVATE mpId] longValue]; short low = (short)[configuration[@"lo"] integerValue]; short high = (short)[configuration[@"hi"] integerValue]; @@ -1976,7 +1976,7 @@ - (void)configureKits:(NSArray *)kitConfigurations { self.originalConfig = kitConfigurations; NSPredicate *predicate; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSDictionary *userAttributes = userDefaults[kMPUserAttributeKey]; NSArray *userIdentities = userDefaults[kMPUserIdentityArrayKey]; NSArray *supportedKits = [self supportedKits]; @@ -2522,7 +2522,7 @@ - (void)forwardSDKCall:(SEL)selector batch:(NSDictionary *)batch kitHandler:(voi return nil; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSArray *> *userIdentities = userDefaults[kMPUserIdentityArrayKey]; __block NSMutableArray *forwardUserIdentities = [[NSMutableArray alloc] initWithCapacity:userIdentities.count]; diff --git a/mParticle-Apple-SDK/MPBackendController.m b/mParticle-Apple-SDK/MPBackendController.m index c9a8a3472..0b5bad557 100644 --- a/mParticle-Apple-SDK/MPBackendController.m +++ b/mParticle-Apple-SDK/MPBackendController.m @@ -6,7 +6,6 @@ #import "MPIConstants.h" #import "MPStateMachine.h" #import "MPNetworkPerformance.h" -#import "MPIUserDefaults.h" #import "MPBreadcrumb.h" #import "MPUpload.h" #import "MPApplication.h" @@ -50,9 +49,10 @@ - (instancetype)initWithUUID:(NSString *)uuid; @interface MParticle () -@property (nonatomic, strong) MPPersistenceController *persistenceController; +@property (nonatomic, strong) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong) MPKitContainer_PRIVATE *kitContainer_PRIVATE; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong) MParticleWebView_PRIVATE *webView; @property (nonatomic, strong, nullable) NSString *dataPlanId; @property (nonatomic, strong, nullable) NSNumber *dataPlanVersion; @@ -171,7 +171,7 @@ - (void)setSession:(MPSession *)session { } - (NSMutableDictionary *)userAttributesForUserId:(NSNumber *)userId { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSMutableDictionary *userAttributes = [[userDefaults mpObjectForKey:kMPUserAttributeKey userId:userId] mutableCopy]; if (userAttributes) { Class NSStringClass = [NSString class]; @@ -189,7 +189,7 @@ - (void)setSession:(MPSession *)session { - (NSMutableArray *> *)identitiesForUserId:(NSNumber *)userId { NSMutableArray *userIdentities = [[NSMutableArray alloc] initWithCapacity:10]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSArray *userIdentityArray = [userDefaults mpObjectForKey:kMPUserIdentityArrayKey userId:userId]; if (userIdentityArray) { [userIdentities addObjectsFromArray:userIdentityArray]; @@ -218,7 +218,7 @@ - (void)setSession:(MPSession *)session { - (NSMutableArray *> *)userIdentitiesForUserId:(NSNumber *)userId { NSMutableArray *identities = [[NSMutableArray alloc] initWithCapacity:10]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSArray *identityArray = [userDefaults mpObjectForKey:kMPUserIdentityArrayKey userId:userId]; if (identityArray) { [identities addObjectsFromArray:identityArray]; @@ -239,7 +239,7 @@ - (void)setSession:(MPSession *)session { #pragma mark Private methods - (void)confirmEndSessionMessage:(MPSession *)session { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; MPMessage *message = [persistence fetchSessionEndMessageInSession:session]; if (!message) { @@ -412,7 +412,7 @@ - (void)processDidFinishLaunching:(NSNotification *)notification { - (void)processOpenSessionsEndingCurrent:(BOOL)endCurrentSession completionHandler:(void (^)(void))completionHandler { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSMutableArray *sessions = [persistence fetchSessions]; if (endCurrentSession) { @@ -496,7 +496,7 @@ - (void)setUserAttributeChange:(MPUserAttributeChange *)userAttributeChange comp return; } - NSMutableDictionary *userAttributes = [self userAttributesForUserId:[MPPersistenceController mpId]]; + NSMutableDictionary *userAttributes = [self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; id userAttributeValue = nil; NSString *localKey = [userAttributes caseInsensitiveKey:userAttributeChange.key]; @@ -560,7 +560,7 @@ - (void)setUserAttributeChange:(MPUserAttributeChange *)userAttributeChange comp [self logUserAttributeChange:userAttributeChange]; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPUserAttributeKey] = userAttributesCopy; [userDefaults synchronize]; @@ -616,7 +616,7 @@ - (void)skipNextUpload { } - (void)prepareBatchesForUpload:(MPUploadSettings *)uploadSettings { - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; //Fetch all stored messages (1) NSDictionary *mpidMessages = [persistence fetchMessagesForUploading]; @@ -667,10 +667,10 @@ - (void)prepareBatchesForUpload:(MPUploadSettings *)uploadSettings { - (void)uploadBatchesWithCompletionHandler:(void(^)(BOOL success))completionHandler { // Prepare upload records - [self prepareBatchesForUpload:[MPUploadSettings currentUploadSettings]]; + [self prepareBatchesForUpload:[MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]]; const void (^completionHandlerCopy)(BOOL) = [completionHandler copy]; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; if (skipNextUpload) { skipNextUpload = NO; @@ -863,9 +863,9 @@ - (void)beginSessionWithIsManual:(BOOL)isManual date:(NSDate *)date { } MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance].stateMachine; - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; - NSNumber *mpId = [MPPersistenceController mpId]; + NSNumber *mpId = [MPPersistenceController_PRIVATE mpId]; date = date ?: [NSDate date]; if (tempSession) { _session = [[MPSession alloc] initWithStartTime:[date timeIntervalSince1970] userId:mpId uuid:tempSession.UUID]; @@ -1085,13 +1085,13 @@ - (NSNumber *)incrementUserAttribute:(NSString *)key byValue:(NSNumber *)value { NSAssert([value isKindOfClass:[NSNumber class]], @"'value' must be a number."); NSDate *timestamp = [NSDate date]; - NSString *localKey = [[self userAttributesForUserId:[MPPersistenceController mpId]] caseInsensitiveKey:key]; + NSString *localKey = [[self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]] caseInsensitiveKey:key]; if (!localKey) { [self setUserAttribute:key value:value timestamp:timestamp completionHandler:nil]; return value; } - id currentValue = [self userAttributesForUserId:[MPPersistenceController mpId]][localKey]; + id currentValue = [self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]][localKey]; if (currentValue && ![currentValue isKindOfClass:[NSNumber class]]) { return nil; } else if (MPIsNull(currentValue)) { @@ -1102,7 +1102,7 @@ - (NSNumber *)incrementUserAttribute:(NSString *)key byValue:(NSNumber *)value { NSDecimalNumber *newValue = [[NSDecimalNumber alloc] initWithString:[(NSNumber *)currentValue stringValue]]; newValue = [newValue decimalNumberByAdding:incrementValue]; - NSMutableDictionary *userAttributes = [self userAttributesForUserId:[MPPersistenceController mpId]]; + NSMutableDictionary *userAttributes = [self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]]; userAttributes[localKey] = newValue; NSMutableDictionary *userAttributesCopy = [[NSMutableDictionary alloc] initWithCapacity:userAttributes.count]; @@ -1117,11 +1117,11 @@ - (NSNumber *)incrementUserAttribute:(NSString *)key byValue:(NSNumber *)value { } } - MPUserAttributeChange *userAttributeChange = [[MPUserAttributeChange alloc] initWithUserAttributes:[[self userAttributesForUserId:[MPPersistenceController mpId]] copy] key:key value:newValue]; + MPUserAttributeChange *userAttributeChange = [[MPUserAttributeChange alloc] initWithUserAttributes:[[self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]] copy] key:key value:newValue]; userAttributeChange.timestamp = timestamp; [self setUserAttributeChange:userAttributeChange completionHandler:nil]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPUserAttributeKey] = userAttributesCopy; [userDefaults synchronize]; @@ -1243,7 +1243,7 @@ - (void)logCrash:(NSString *)message stackTrace:(NSString *)stackTrace plCrashR messageInfo[kMPPLCrashReport] = plCrashReportBase64; } - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSArray *fetchedbreadcrumbs = [persistence fetchBreadcrumbs]; if (fetchedbreadcrumbs) { NSMutableArray *breadcrumbs = [[NSMutableArray alloc] initWithCapacity:fetchedbreadcrumbs.count]; @@ -1269,7 +1269,7 @@ - (void)logCrash:(NSString *)message stackTrace:(NSString *)stackTrace plCrashR MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeCrashReport session:crashSession messageInfo:messageInfo]; MPMessage *crashMessage = [messageBuilder build]; - NSInteger maxBytes = [MPPersistenceController maxBytesPerEvent:crashMessage.messageType]; + NSInteger maxBytes = [MPPersistenceController_PRIVATE maxBytesPerEvent:crashMessage.messageType]; if(crashMessage.messageData.length > maxBytes) { NSInteger bytesToTruncate = crashMessage.messageData.length - maxBytes; NSInteger bytesToRetain = plCrashReportBase64.length - bytesToTruncate; @@ -1464,9 +1464,9 @@ - (void)startWithKey:(NSString *)apiKey secret:(NSString *)secret networkOptions } } - MPConsentState *storedConsentState = [MPPersistenceController consentStateForMpid:[MPPersistenceController mpId]]; + MPConsentState *storedConsentState = [MPPersistenceController_PRIVATE consentStateForMpid:[MPPersistenceController_PRIVATE mpId]]; if (consentState != nil && storedConsentState == nil) { - [MPPersistenceController setConsentState:consentState forMpid:[MPPersistenceController mpId]]; + [MPPersistenceController_PRIVATE setConsentState:consentState forMpid:[MPPersistenceController_PRIVATE mpId]]; } if (![MParticle sharedInstance].stateMachine.optOut) { @@ -1489,24 +1489,24 @@ - (void)startWithKey:(NSString *)apiKey secret:(NSString *)secret networkOptions } dispatch_async([MParticle messageQueue], ^{ - [MParticle sharedInstance].persistenceController = [[MPPersistenceController alloc] init]; + [MParticle sharedInstance].persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; // Check if we've switched workspaces on startup - MPUploadSettings *lastUploadSettings = [[MPIUserDefaults standardUserDefaults] lastUploadSettings]; + MPUploadSettings *lastUploadSettings = [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] lastUploadSettings]; if (![lastUploadSettings.apiKey isEqualToString:apiKey]) { // Different workspace, so batch previous messages under old upload settings before starting [self prepareBatchesForUpload:lastUploadSettings]; // Delete the cached config - [MPIUserDefaults deleteConfig]; + [MPUserDefaults deleteConfig]; } // Cache the upload settings in case we switch workspaces on startup MPUploadSettings *uploadSettings = [[MPUploadSettings alloc] initWithApiKey:apiKey secret:secret networkOptions:networkOptions]; - [[MPIUserDefaults standardUserDefaults] setLastUploadSettings:uploadSettings]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setLastUploadSettings:uploadSettings]; // Restore cached config if exists - [MPIUserDefaults restore]; + (void)[MPUserDefaults restore]; if (shouldBeginSession) { [self beginSessionWithIsManual:!MParticle.sharedInstance.automaticSessionTracking date:date]; @@ -1555,7 +1555,7 @@ - (void)saveMessage:(MPMessage *)message updateSession:(BOOL)updateSession { self.timeOfLastEventInBackground = lastEventTimestamp; } - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; MPMessageType messageTypeCode = [MPMessageBuilder messageTypeForString:message.messageType]; @@ -1662,7 +1662,7 @@ - (void)setUserTag:(NSString *)key timestamp:(NSDate *)timestamp completionHandl return; } - MPUserAttributeChange *userAttributeChange = [[MPUserAttributeChange alloc] initWithUserAttributes:[[self userAttributesForUserId:[MPPersistenceController mpId]] copy] key:keyCopy value:[NSNull null]]; + MPUserAttributeChange *userAttributeChange = [[MPUserAttributeChange alloc] initWithUserAttributes:[[self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]] copy] key:keyCopy value:[NSNull null]]; userAttributeChange.timestamp = timestamp; [self setUserAttributeChange:userAttributeChange completionHandler:completionHandler]; } @@ -1688,7 +1688,7 @@ - (void)setUserAttribute:(NSString *)key value:(id)value timestamp:(NSDate *)tim return; } - MPUserAttributeChange *userAttributeChange = [[MPUserAttributeChange alloc] initWithUserAttributes:[[self userAttributesForUserId:[MPPersistenceController mpId]] copy] key:keyCopy value:value]; + MPUserAttributeChange *userAttributeChange = [[MPUserAttributeChange alloc] initWithUserAttributes:[[self userAttributesForUserId:[MPPersistenceController_PRIVATE mpId]] copy] key:keyCopy value:value]; userAttributeChange.timestamp = timestamp; [self setUserAttributeChange:userAttributeChange completionHandler:completionHandler]; } @@ -1715,7 +1715,7 @@ - (void)setUserAttribute:(nonnull NSString *)key values:(nullable NSArray= 0 && authorizationState.integerValue <= 3) { @@ -556,7 +556,7 @@ - (NSNumber *)attAuthorizationTimestamp { return _attAuthorizationTimestamp; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSNumber *authorizationStateTimestamp = userDefaults[kMPATTTimestamp]; _attAuthorizationTimestamp = authorizationStateTimestamp; @@ -569,7 +569,7 @@ - (void)setAttAuthorizationStatus:(NSNumber *)authorizationState { _attAuthorizationStatus = authorizationState; _attAuthorizationTimestamp = MPCurrentEpochInMilliseconds; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPATT] = _attAuthorizationStatus; userDefaults[kMPATTTimestamp] = _attAuthorizationTimestamp; @@ -586,7 +586,7 @@ - (void)setAttAuthorizationTimestamp:(NSNumber *)timestamp { if (timestamp.doubleValue != _attAuthorizationTimestamp.doubleValue) { _attAuthorizationTimestamp = timestamp; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPATTTimestamp] = _attAuthorizationTimestamp; } } @@ -598,7 +598,7 @@ - (NSString *)pushNotificationMode { [self willChangeValueForKey:@"pushNotificationMode"]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSString *pushNotificationMode = userDefaults[kMPRemoteConfigPushNotificationModeKey]; if (pushNotificationMode) { _pushNotificationMode = pushNotificationMode; @@ -620,7 +620,7 @@ - (void)setPushNotificationMode:(NSString *)pushNotificationMode { _pushNotificationMode = pushNotificationMode; [self didChangeValueForKey:@"pushNotificationMode"]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPRemoteConfigPushNotificationModeKey] = _pushNotificationMode; } diff --git a/mParticle-Apple-SDK/Network/MPNetworkCommunication.m b/mParticle-Apple-SDK/Network/MPNetworkCommunication.m index de97c85b5..408dfb0e7 100644 --- a/mParticle-Apple-SDK/Network/MPNetworkCommunication.m +++ b/mParticle-Apple-SDK/Network/MPNetworkCommunication.m @@ -12,7 +12,6 @@ #import "MPILogger.h" #import "MPConsumerInfo.h" #import "MPPersistenceController.h" -#import "MPIUserDefaults.h" #import "MParticleSwift.h" #import "MPIdentityApiRequest.h" #import "mParticle.h" @@ -59,7 +58,7 @@ @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, readonly) MPBackendController_PRIVATE *backendController; @@ -278,13 +277,13 @@ - (MPURL *)modifyURL { } else { identityHost = [MParticle sharedInstance].networkOptions.identityHost ?: self.defaultIdentityHost; } - NSString *urlString = [NSString stringWithFormat:modifyURLFormat, kMPURLScheme, self.defaultIdentityHost, kMPIdentityVersion, [MPPersistenceController mpId], pathComponent]; + NSString *urlString = [NSString stringWithFormat:modifyURLFormat, kMPURLScheme, self.defaultIdentityHost, kMPIdentityVersion, [MPPersistenceController_PRIVATE mpId], pathComponent]; NSURL *defaultURL = [NSURL URLWithString:urlString]; if ([MParticle sharedInstance].networkOptions.overridesIdentitySubdirectory) { - urlString = [NSString stringWithFormat:modifyURLFormatOverride, kMPURLScheme, identityHost, [MPPersistenceController mpId], pathComponent]; + urlString = [NSString stringWithFormat:modifyURLFormatOverride, kMPURLScheme, identityHost, [MPPersistenceController_PRIVATE mpId], pathComponent]; } else { - urlString = [NSString stringWithFormat:modifyURLFormat, kMPURLScheme, identityHost, kMPIdentityVersion, [MPPersistenceController mpId], pathComponent]; + urlString = [NSString stringWithFormat:modifyURLFormat, kMPURLScheme, identityHost, kMPIdentityVersion, [MPPersistenceController_PRIVATE mpId], pathComponent]; } NSURL *modifiedURL = [NSURL URLWithString:urlString]; @@ -415,8 +414,8 @@ - (NSNumber *)maxAgeForCache:(nonnull NSString *)cache { } - (void)requestConfig:(nullable NSObject *)connector withCompletionHandler:(void(^)(BOOL success))completionHandler { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - BOOL shouldSendRequest = [userDefaults isConfigurationExpired] || [userDefaults isConfigurationParametersOutdated]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; + BOOL shouldSendRequest = [userDefaults isConfigurationExpired]; if (!shouldSendRequest) { completionHandler(YES); @@ -459,8 +458,8 @@ - (void)requestConfig:(nullable NSObject *)connector withCo MPILogVerbose(@"Config Response Code: %ld, Execution Time: %.2fms", (long)responseCode, ([[NSDate date] timeIntervalSince1970] - start) * 1000.0); if (responseCode == HTTPStatusCodeNotModified) { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - [userDefaults setConfiguration:[userDefaults getConfiguration] eTag:userDefaults[kMPHTTPETagHeaderKey] requestTimestamp:[[NSDate date] timeIntervalSince1970] currentAge:ageString maxAge:maxAge]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; + [userDefaults setConfiguration:[userDefaults getConfiguration] eTag:userDefaults[kMPHTTPETagHeaderKey] requestTimestamp:[[NSDate date] timeIntervalSince1970] currentAge:ageString.doubleValue maxAge:maxAge]; completionHandler(YES); [MPListenerController.sharedInstance onNetworkRequestFinished:MPEndpointConfig url:self.configURL.url.absoluteString body:[NSDictionary dictionary] responseCode:responseCode]; @@ -498,8 +497,8 @@ - (void)requestConfig:(nullable NSObject *)connector withCo MPResponseConfig *responseConfig = [[MPResponseConfig alloc] initWithConfiguration:configurationDictionary dataReceivedFromServer:YES stateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController]; MPILogDebug(@"MPResponseConfig init: %@", responseConfig.description); - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - [userDefaults setConfiguration:configurationDictionary eTag:eTag requestTimestamp:[[NSDate date] timeIntervalSince1970] currentAge:ageString maxAge:maxAge]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; + [userDefaults setConfiguration:configurationDictionary eTag:eTag requestTimestamp:[[NSDate date] timeIntervalSince1970] currentAge:ageString.doubleValue maxAge:maxAge]; } completionHandler(success); @@ -950,7 +949,7 @@ - (void)identityApiRequestWithURL:(NSURL*)url identityRequest:(MPIdentityHTTPBas } - (void)identify:(MPIdentityApiRequest *_Nonnull)identifyRequest completion:(nullable MPIdentityApiManagerCallback)completion { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (!userDefaults[kMPATT] && identifyRequest.identities[@(MPIdentityIOSAdvertiserId)]) { MPILogDebug(@"The IDFA was supplied but the App Tracking Transparency Status not set with [[MParticle sharedInstance] setATTStatus:withATTStatusTimestampMillis:]"); } @@ -960,7 +959,7 @@ - (void)identify:(MPIdentityApiRequest *_Nonnull)identifyRequest completion:(nul } - (void)login:(MPIdentityApiRequest *_Nullable)loginRequest completion:(nullable MPIdentityApiManagerCallback)completion { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (!userDefaults[kMPATT] && loginRequest.identities[@(MPIdentityIOSAdvertiserId)]) { MPILogDebug(@"The IDFA was supplied but the App Tracking Transparency Status not set with [[MParticle sharedInstance] setATTStatus:withATTStatusTimestampMillis:]"); } @@ -971,7 +970,7 @@ - (void)login:(MPIdentityApiRequest *_Nullable)loginRequest completion:(nullable - (void)logout:(MPIdentityApiRequest *_Nullable)logoutRequest completion:(nullable MPIdentityApiManagerCallback)completion { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (!userDefaults[kMPATT] && logoutRequest.identities[@(MPIdentityIOSAdvertiserId)]) { MPILogDebug(@"The IDFA was supplied but the App Tracking Transparency Status not set with [[MParticle sharedInstance] setATTStatus:withATTStatusTimestampMillis:]"); } @@ -981,7 +980,7 @@ - (void)logout:(MPIdentityApiRequest *_Nullable)logoutRequest completion:(nullab } - (void)modify:(MPIdentityApiRequest *_Nonnull)modifyRequest completion:(nullable MPIdentityApiManagerModifyCallback)completion { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (!userDefaults[kMPATT] && modifyRequest.identities[@(MPIdentityIOSAdvertiserId)]) { MPILogDebug(@"The IDFA was supplied but the App Tracking Transparency Status not set with [[MParticle sharedInstance] setATTStatus:withATTStatusTimestampMillis:]"); } @@ -1047,13 +1046,13 @@ + (void)parseConfiguration:(nonnull NSDictionary *)configuration { return; } - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; // Consumer Information MPConsumerInfo *consumerInfo = [MParticle sharedInstance].stateMachine.consumerInfo; [consumerInfo updateWithConfiguration:configuration[kMPRemoteConfigConsumerInfoKey]]; [persistence updateConsumerInfo:consumerInfo]; - MPConsumerInfo *persistenceInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController mpId]]; + MPConsumerInfo *persistenceInfo = [persistence fetchConsumerInfoForUserId:[MPPersistenceController_PRIVATE mpId]]; if (persistenceInfo.cookies != nil) { [MParticle sharedInstance].stateMachine.consumerInfo.cookies = persistenceInfo.cookies; } diff --git a/mParticle-Apple-SDK/Network/MPURLRequestBuilder.m b/mParticle-Apple-SDK/Network/MPURLRequestBuilder.m index cca4ffa24..f78ca726f 100644 --- a/mParticle-Apple-SDK/Network/MPURLRequestBuilder.m +++ b/mParticle-Apple-SDK/Network/MPURLRequestBuilder.m @@ -2,7 +2,6 @@ #import #import "MPIConstants.h" #import -#import "MPIUserDefaults.h" #import "MPKitContainer.h" #import "MPExtensionProtocol.h" #import "MPILogger.h" @@ -16,6 +15,7 @@ @interface MParticle () @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong, readonly) MParticleWebView_PRIVATE *webView; @end @@ -198,7 +198,7 @@ - (NSMutableURLRequest *)build { NSString *environment = [NSString stringWithFormat:@"%d", (int)[MPStateMachine_PRIVATE environment]]; [urlRequest setValue:environment forHTTPHeaderField:@"x-mp-env"]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSString *eTag = userDefaults[kMPHTTPETagHeaderKey]; NSDictionary *config = [userDefaults getConfiguration]; if (eTag && config) { diff --git a/mParticle-Apple-SDK/Notifications/MPNotificationController.m b/mParticle-Apple-SDK/Notifications/MPNotificationController.m index 7f92e3834..2a5574946 100644 --- a/mParticle-Apple-SDK/Notifications/MPNotificationController.m +++ b/mParticle-Apple-SDK/Notifications/MPNotificationController.m @@ -1,9 +1,9 @@ #import "MPNotificationController.h" #import "MPIConstants.h" #import "MPPersistenceController.h" -#import "MPIUserDefaults.h" #import "mParticle.h" #import "MPNetworkCommunication.h" +#import "MParticleSwift.h" @interface MPNotificationController_PRIVATE() { } @@ -13,6 +13,7 @@ @interface MPNotificationController_PRIVATE() { @interface MParticle () + (dispatch_queue_t)messageQueue; +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @end @@ -37,7 +38,7 @@ - (instancetype)init { #pragma mark Public static methods + (NSData *)deviceToken { #ifndef MP_UNIT_TESTING - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; deviceToken = userDefaults[kMPDeviceTokenKey]; #else deviceToken = [@"<000000000000000000000000000000>" dataUsingEncoding:NSUTF8StringEncoding]; @@ -62,12 +63,12 @@ + (void)setDeviceToken:(NSData *)devToken { NSString *oldTokenString = nil; if (newDeviceToken) { deviceTokenDictionary[kMPRemoteNotificationDeviceTokenKey] = newDeviceToken; - newTokenString = [MPIUserDefaults stringFromDeviceToken:newDeviceToken]; + newTokenString = [MPUserDefaults stringFromDeviceToken:newDeviceToken]; } if (oldDeviceToken) { deviceTokenDictionary[kMPRemoteNotificationOldDeviceTokenKey] = oldDeviceToken; - oldTokenString = [MPIUserDefaults stringFromDeviceToken:oldDeviceToken]; + oldTokenString = [MPUserDefaults stringFromDeviceToken:oldDeviceToken]; } [[NSNotificationCenter defaultCenter] postNotificationName:kMPRemoteNotificationDeviceTokenNotification @@ -81,7 +82,7 @@ + (void)setDeviceToken:(NSData *)devToken { } #ifndef MP_UNIT_TESTING - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[kMPDeviceTokenKey] = deviceToken; [userDefaults synchronize]; #endif diff --git a/mParticle-Apple-SDK/Persistence/MPDatabaseMigrationController.m b/mParticle-Apple-SDK/Persistence/MPDatabaseMigrationController.m index 653a15e07..e93bd3f2e 100644 --- a/mParticle-Apple-SDK/Persistence/MPDatabaseMigrationController.m +++ b/mParticle-Apple-SDK/Persistence/MPDatabaseMigrationController.m @@ -1,7 +1,6 @@ #import "MPDatabaseMigrationController.h" #import #import "MPSession.h" -#import "MPIUserDefaults.h" #import "mParticle.h" #import "MPBackendController.h" #import "MPPersistenceController.h" @@ -9,10 +8,11 @@ #import "MPILogger.h" #import "MPStateMachine.h" #import "MPUpload.h" +#import "MParticleSwift.h" @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @@ -87,11 +87,12 @@ - (void)deleteRecordsOlderThan:(NSTimeInterval)timestamp version:(NSNumber *)old - (void)migrateUserDefaultsWithVersion:(NSNumber *)oldVersion { NSInteger oldVersionValue = [oldVersion integerValue]; + MPUserDefaults *defaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (oldVersionValue < 26) { - [[MPIUserDefaults standardUserDefaults] migrateUserKeysWithUserId:[MPPersistenceController mpId]]; + [defaults migrateUserKeysWithUserId:[MPPersistenceController_PRIVATE mpId]]; } if (oldVersionValue < 28) { - [[MPIUserDefaults standardUserDefaults] migrateFirstLastSeenUsers]; + [defaults migrateFirstLastSeenUsers]; } } @@ -150,7 +151,7 @@ - (void)migrateSessionsFromDatabase:(sqlite3 *)oldDatabase version:(NSNumber *)o NSTimeInterval length = 0; NSNumber *mpId; if (oldVersionValue < 26) { - mpId = [MPPersistenceController mpId]; + mpId = [MPPersistenceController_PRIVATE mpId]; } else { mpId = @(sqlite3_column_int64(selectStatementHandle, 10)); } @@ -233,7 +234,7 @@ - (void)migrateMessagesFromDatabase:(sqlite3 *)oldDatabase version:(NSNumber *)o } if (oldVersionValue < 26) { - mpId = [MPPersistenceController mpId]; + mpId = [MPPersistenceController_PRIVATE mpId]; } else { mpId = @(sqlite3_column_int64(selectStatementHandle, 6)); } @@ -298,7 +299,7 @@ - (void)migrateUploadsFromDatabase:(sqlite3 *)oldDatabase version:(NSNumber *)ol sqlite3_prepare_v2(oldDatabase, selectStatement, -1, &selectStatementHandle, NULL); sqlite3_prepare_v2(newDatabase, insertStatement, -1, &insertStatementHandle, NULL); - MPUploadSettings *uploadSettings = [MPUploadSettings currentUploadSettings]; + MPUploadSettings *uploadSettings = [MPUploadSettings currentUploadSettingsWithStateMachine:[MParticle sharedInstance].stateMachine networkOptions:[MParticle sharedInstance].networkOptions]; while (sqlite3_step(selectStatementHandle) == SQLITE_ROW) { uuid = (const char *)sqlite3_column_text(selectStatementHandle, 0); sqlite3_bind_text(insertStatementHandle, 1, uuid, -1, SQLITE_TRANSIENT); // uuid @@ -395,7 +396,7 @@ - (void)migrateForwardingRecordsFromDatabase:(sqlite3 *)oldDatabase version:(NSN sqlite3_bind_int(insertStatementHandle, 1, sqlite3_column_int(selectStatementHandle, 0)); // _id sqlite3_bind_blob(insertStatementHandle, 2, sqlite3_column_blob(selectStatementHandle, 1), sqlite3_column_bytes(selectStatementHandle, 1), SQLITE_TRANSIENT); // forwarding_data if (oldVersionValue < 26) { - mpId = [MPPersistenceController mpId]; + mpId = [MPPersistenceController_PRIVATE mpId]; } else { mpId = @(sqlite3_column_int64(selectStatementHandle, 2)); @@ -464,7 +465,7 @@ - (void)migrateConsumerInfoFromDatabase:(sqlite3 *)oldDatabase version:(NSNumber sqlite3_bind_text(insertStatementHandle, 6, (const char *)sqlite3_column_text(selectStatementHandle, 5), -1, SQLITE_TRANSIENT); // name if (oldVersionValue < 26) { mpId = @(userId); - [MPPersistenceController setMpid:mpId]; + [MPPersistenceController_PRIVATE setMpid:mpId]; } else { mpId = @(sqlite3_column_int64(selectStatementHandle, 6)); } diff --git a/mParticle-Apple-SDK/Persistence/MPIdentityCaching.m b/mParticle-Apple-SDK/Persistence/MPIdentityCaching.m index 1a71998fa..4f6d3a434 100644 --- a/mParticle-Apple-SDK/Persistence/MPIdentityCaching.m +++ b/mParticle-Apple-SDK/Persistence/MPIdentityCaching.m @@ -6,10 +6,17 @@ // #import "MPIdentityCaching.h" -#import "MPIUserDefaults.h" #import "MPILogger.h" #import "mParticle.h" #import +#import "MParticleSwift.h" + +@interface MParticle () + +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; + +@end // User defaults key static NSString *const kMPIdentityCachingCachedIdentityCallsKey = @"kMPIdentityCachingCachedIdentityCallsKey"; @@ -176,11 +183,11 @@ + (void)clearExpiredCache { #pragma mark - Private + (nullable NSDictionary *)getCache { - return [[MPIUserDefaults standardUserDefaults] mpObjectForKey:kMPIdentityCachingCachedIdentityCallsKey userId:@0]; + return [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] mpObjectForKey:kMPIdentityCachingCachedIdentityCallsKey userId:@0]; } + (void)setCache:(nullable NSDictionary *)cache { - [[MPIUserDefaults standardUserDefaults] setMPObject:cache forKey:kMPIdentityCachingCachedIdentityCallsKey userId:@0]; + [[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] setMPObject:cache forKey:kMPIdentityCachingCachedIdentityCallsKey userId:@0]; } + (nullable NSString *)keyWithEndpoint:(MPEndpoint)endpoint identities:(nonnull NSDictionary *)identities { diff --git a/mParticle-Apple-SDK/Persistence/MPPersistenceController.mm b/mParticle-Apple-SDK/Persistence/MPPersistenceController.mm index 8a0e6b731..2ed9be3f5 100644 --- a/mParticle-Apple-SDK/Persistence/MPPersistenceController.mm +++ b/mParticle-Apple-SDK/Persistence/MPPersistenceController.mm @@ -11,7 +11,6 @@ #import "MPForwardRecord.h" #import "MPIntegrationAttributes.h" #import "MPPersistenceController.h" -#import "MPIUserDefaults.h" #import "mParticle.h" #import "MPIConstants.h" #import "MPConsentSerialization.h" @@ -20,6 +19,8 @@ #import "MPKitFilter.h" #import "MPDevice.h" #import "MPApplication.h" +#import "MParticleSwift.h" +#import "MParticleUserNotification.h" #import #import @@ -57,8 +58,9 @@ typedef NS_ENUM(NSInteger, MPDatabaseState) { @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @end @@ -70,7 +72,7 @@ - (nonnull instancetype)initWithMessageType:(MPMessageType)messageType execStatu - (nonnull instancetype)initWithId:(int64_t)forwardRecordId data:(nonnull NSData *)data mpid:(nonnull NSNumber *)mpid; @end -@interface MPPersistenceController() { +@interface MPPersistenceController_PRIVATE() { BOOL databaseOpen; sqlite3 *mParticleDB; } @@ -79,12 +81,12 @@ @interface MPPersistenceController() { @end -@implementation MPPersistenceController +@implementation MPPersistenceController_PRIVATE @synthesize databasePath = _databasePath; + (void)initialize { - if (self == [MPPersistenceController class]) { + if (self == [MPPersistenceController_PRIVATE class]) { databaseVersions = @[@3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23, @24, @25, @26, @27, @28, @29, @30, @31]; } } @@ -120,7 +122,7 @@ - (void)migrateDatabaseIfNeeded { } + (NSNumber *)mpId { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSNumber *mpId = userDefaults[@"mpid"]; if (mpId == nil) { mpId = @0; @@ -130,13 +132,13 @@ + (NSNumber *)mpId { } + (void)setMpid:(NSNumber *)mpId { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; userDefaults[@"mpid"] = mpId; [userDefaults synchronize]; } + (nullable MPConsentState *)consentStateForMpid:(nonnull NSNumber *)mpid { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSString *string = [userDefaults mpObjectForKey:kMPConsentStateKey userId:mpid]; if (!string) { return nil; @@ -151,7 +153,7 @@ + (nullable MPConsentState *)consentStateForMpid:(nonnull NSNumber *)mpid { } + (void)setConsentState:(nullable MPConsentState *)state forMpid:(nonnull NSNumber *)mpid { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (!state) { [userDefaults removeMPObjectForKey:kMPConsentStateKey userId:mpid]; [userDefaults synchronize]; @@ -305,7 +307,7 @@ - (void)saveCookie:(MPCookie *)cookie forConsumerInfo:(MPConsumerInfo *)consumer params.push_back("'" + string([cookie.name cStringUsingEncoding:NSUTF8StringEncoding]) + "'"); fields.push_back("mpid"); - params.push_back("'" + string([[NSString stringWithFormat:@"%@", [MPPersistenceController mpId]] cStringUsingEncoding:NSUTF8StringEncoding]) + "'"); + params.push_back("'" + string([[NSString stringWithFormat:@"%@", [MPPersistenceController_PRIVATE mpId]] cStringUsingEncoding:NSUTF8StringEncoding]) + "'"); string sqlStatement = "INSERT INTO cookies (consumer_info_id"; for (auto field : fields) { @@ -871,7 +873,7 @@ - (void)deleteUploadId:(int64_t)uploadId { const string sqlStatement = "SELECT _id, session_uuid, uuid, breadcrumb_data, timestamp FROM breadcrumbs WHERE mpid = ? ORDER BY _id"; if (sqlite3_prepare_v2(mParticleDB, sqlStatement.c_str(), (int)sqlStatement.size(), &preparedStatement, NULL) == SQLITE_OK) { - sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController_PRIVATE mpId] longLongValue]); while (sqlite3_step(preparedStatement) == SQLITE_ROW) { MPBreadcrumb *breadcrumb = [[MPBreadcrumb alloc] initWithSessionUUID:stringValue(preparedStatement, 1) @@ -1092,9 +1094,9 @@ - (NSMutableDictionary *)fetchMessagesForUploading { ORDER BY session_number"; if (sqlite3_prepare_v2(mParticleDB, sqlStatement.c_str(), (int)sqlStatement.size(), &preparedStatement, NULL) == SQLITE_OK) { - sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController mpId] longLongValue]); - sqlite3_bind_int64(preparedStatement, 2, [[MPPersistenceController mpId] longLongValue]); - sqlite3_bind_int64(preparedStatement, 3, [[MPPersistenceController mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController_PRIVATE mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 2, [[MPPersistenceController_PRIVATE mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 3, [[MPPersistenceController_PRIVATE mpId] longLongValue]); while (sqlite3_step(preparedStatement) == SQLITE_ROW) { MPSession *crashSession = [[MPSession alloc] initWithSessionId:int64Value(preparedStatement, 0) @@ -1136,7 +1138,7 @@ - (nullable MPSession *)fetchPreviousSession { const string sqlStatement = "SELECT session_id, uuid, background_time, start_time, end_time, attributes_data, session_number, number_interruptions, event_count, suspend_time, length, mpid, session_user_ids FROM previous_session WHERE mpid = ?"; if (sqlite3_prepare_v2(mParticleDB, sqlStatement.c_str(), (int)sqlStatement.size(), &preparedStatement, NULL) == SQLITE_OK) { - sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController_PRIVATE mpId] longLongValue]); if (sqlite3_step(preparedStatement) == SQLITE_ROW) { previousSession = [[MPSession alloc] initWithSessionId:int64Value(preparedStatement, 0) @@ -1246,7 +1248,7 @@ - (MPMessage *)fetchSessionEndMessageInSession:(MPSession *)session { if (sqlite3_prepare_v2(mParticleDB, sqlStatement.c_str(), (int)sqlStatement.size(), &preparedStatement, NULL) == SQLITE_OK) { sqlite3_bind_int64(preparedStatement, 1, session.sessionId); sqlite3_bind_int(preparedStatement, 2, MPUploadStatusUploaded); - sqlite3_bind_int64(preparedStatement, 3, [[MPPersistenceController mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 3, [[MPPersistenceController_PRIVATE mpId] longLongValue]); while (sqlite3_step(preparedStatement) == SQLITE_ROW) { MPMessage *message = [[MPMessage alloc] initWithSessionId:@(session.sessionId) @@ -1419,7 +1421,7 @@ - (void)saveBreadcrumb:(MPMessage *)message { sqlite3_bind_double(preparedStatement, 3, message.timestamp); sqlite3_bind_blob(preparedStatement, 4, [message.messageData bytes], (int)[message.messageData length], SQLITE_STATIC); sqlite3_bind_int64(preparedStatement, 5, 0); //session_number Deprecated - sqlite3_bind_int64(preparedStatement, 6, [[MPPersistenceController mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 6, [[MPPersistenceController_PRIVATE mpId] longLongValue]); if (sqlite3_step(preparedStatement) != SQLITE_DONE) { MPILogError(@"Error while storing breadcrumb: %s", sqlite3_errmsg(mParticleDB)); @@ -1438,8 +1440,8 @@ - (void)saveBreadcrumb:(MPMessage *)message { sqlStatement = "DELETE FROM breadcrumbs WHERE mpid = ? AND _id NOT IN (SELECT _id FROM breadcrumbs WHERE mpid = ? ORDER BY _id DESC LIMIT ?)"; if (sqlite3_prepare_v2(mParticleDB, sqlStatement.c_str(), (int)sqlStatement.size(), &preparedStatement, NULL) == SQLITE_OK) { - sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController mpId] longLongValue]); - sqlite3_bind_int64(preparedStatement, 2, [[MPPersistenceController mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 1, [[MPPersistenceController_PRIVATE mpId] longLongValue]); + sqlite3_bind_int64(preparedStatement, 2, [[MPPersistenceController_PRIVATE mpId] longLongValue]); sqlite3_bind_int(preparedStatement, 3, MaxBreadcrumbs); if (sqlite3_step(preparedStatement) != SQLITE_DONE) { @@ -1588,7 +1590,7 @@ - (void)saveMessage:(MPMessage *)message { return; } - NSInteger maxBytes = [MPPersistenceController maxBytesPerEvent:message.messageType]; + NSInteger maxBytes = [MPPersistenceController_PRIVATE maxBytesPerEvent:message.messageType]; if (message == nil || message.messageData.length > maxBytes) { MPILogError(@"Unable to save message that is nil or exceeds max message size!"); return; diff --git a/mParticle-Apple-SDK/Utils/MPApplication.m b/mParticle-Apple-SDK/Utils/MPApplication.m index f73c14840..1b2dd9f2d 100644 --- a/mParticle-Apple-SDK/Utils/MPApplication.m +++ b/mParticle-Apple-SDK/Utils/MPApplication.m @@ -3,11 +3,11 @@ #import #import #import -#import "MPIUserDefaults.h" #import #import "MPStateMachine.h" #import #import "mParticle.h" +#import "mParticleSwift.h" #import "MPIConstants.h" NSString *const kMPApplicationInformationKey = @"ai"; @@ -67,12 +67,13 @@ @interface MParticle () @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @end @interface MPApplication_PRIVATE() { NSDictionary *appInfo; - MPIUserDefaults *userDefaults; + MPUserDefaults *userDefaults; } @end @@ -98,7 +99,8 @@ - (id)init { return nil; } - userDefaults = [MPIUserDefaults standardUserDefaults]; + userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; + return self; } @@ -277,7 +279,7 @@ - (NSString *)version { } - (NSNumber *)sideloadedKitsCount { - NSNumber *sideloadedKitsCount = @([[MPIUserDefaults standardUserDefaults] sideloadedKitsCount]); + NSNumber *sideloadedKitsCount = @([[MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity] sideloadedKitsCount]); return sideloadedKitsCount; } @@ -326,7 +328,7 @@ + (NSString *)appStoreReceipt { } + (void)markInitialLaunchTime { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; NSNumber *initialLaunchTime = userDefaults[kMPAppInitialLaunchTimeKey]; if (initialLaunchTime == nil) { diff --git a/mParticle-Apple-SDK/Utils/MPDevice.m b/mParticle-Apple-SDK/Utils/MPDevice.m index 63fb79bfe..c9dc5f881 100644 --- a/mParticle-Apple-SDK/Utils/MPDevice.m +++ b/mParticle-Apple-SDK/Utils/MPDevice.m @@ -3,7 +3,6 @@ #import #import #import "MPStateMachine.h" -#import "MPIUserDefaults.h" #import #import #import @@ -14,6 +13,7 @@ #import "mParticle.h" #import "MPBackendController.h" #import "MPILogger.h" +#import "MParticleSwift.h" #if TARGET_OS_IOS == 1 #import "MPNotificationController.h" @@ -55,12 +55,6 @@ int main(int argc, char *argv[]); -@interface MParticle () - -@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; - -@end - @interface MPDevice() { NSCalendar *calendar; NSDictionary *deviceInfo; @@ -74,6 +68,7 @@ @interface MPDevice() { @interface MParticle () +@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; @property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @end @@ -202,7 +197,7 @@ - (NSString *)deviceIdentifier { return _deviceIdentifier; } - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; _deviceIdentifier = userDefaults[kMPDeviceIdentifierKey]; if (!_deviceIdentifier) { _deviceIdentifier = [[NSUUID UUID] UUIDString]; @@ -297,7 +292,7 @@ - (NSString *)vendorId { } _vendorId = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; if (_vendorId && ![_vendorId isEqualToString:kMPDeviceInvalidVendorId]) { userDefaults[kMPDeviceAppVendorIdKey] = _vendorId; @@ -525,7 +520,7 @@ - (NSDictionary *)dictionaryRepresentation { if (![MPStateMachine_PRIVATE isAppExtension]) { pushNotificationToken = [MPNotificationController_PRIVATE deviceToken]; if (pushNotificationToken) { - NSString *tokenString = [MPIUserDefaults stringFromDeviceToken:pushNotificationToken]; + NSString *tokenString = [MPUserDefaults stringFromDeviceToken:pushNotificationToken]; if (tokenString) { deviceDictionary[kMPDeviceTokenKey] = tokenString; } diff --git a/mParticle-Apple-SDK/Utils/MPIUserDefaults.h b/mParticle-Apple-SDK/Utils/MPIUserDefaults.h deleted file mode 100644 index e52822732..000000000 --- a/mParticle-Apple-SDK/Utils/MPIUserDefaults.h +++ /dev/null @@ -1,42 +0,0 @@ -#import - -@class MPKitConfiguration; -@class MPUploadSettings; -@class MPResponseConfig; - -@interface MPIUserDefaults : NSObject - -+ (nonnull instancetype)standardUserDefaults; -- (nullable id)mpObjectForKey:(nonnull NSString *)key userId:(nonnull NSNumber *)userId; -- (void)setMPObject:(nullable id)value forKey:(nonnull NSString *)key userId:(nonnull NSNumber *)userId; -- (void)removeMPObjectForKey:(nonnull NSString *)key userId:(nonnull NSNumber *)userId; -- (void)removeMPObjectForKey:(nonnull NSString *)key; -- (nullable id)objectForKeyedSubscript:(nonnull NSString *const)key; -- (void)setObject:(nullable id)obj forKeyedSubscript:(nonnull NSString *)key; -- (void)synchronize; -- (void)migrateUserKeysWithUserId:(nonnull NSNumber *)userId; -- (void)migrateFirstLastSeenUsers; -- (void)setSharedGroupIdentifier:(nullable NSString *)groupIdentifier; -- (void)migrateToSharedGroupIdentifier:(nonnull NSString *)groupIdentifier; -- (void)migrateFromSharedGroupIdentifier; -- (nullable NSDictionary *)getConfiguration; -- (nullable NSArray *)getKitConfigurations; -- (void)setConfiguration:(nonnull NSDictionary *)responseConfiguration eTag:(nonnull NSString *)eTag requestTimestamp:(NSTimeInterval)requestTimestamp currentAge:(nonnull NSString *)currentAge maxAge:(nullable NSNumber *)maxAge; -- (void)migrateConfiguration; -- (void)deleteConfiguration; -- (void)resetDefaults; -- (BOOL)isExistingUserId:(nonnull NSNumber *)userId; -- (nonnull NSArray *)userIDsInUserDefaults; -- (BOOL)isConfigurationExpired; -- (BOOL)isConfigurationParametersOutdated; -- (void)setSideloadedKitsCount:(NSUInteger)sideloadedKitsCount; -- (NSUInteger)sideloadedKitsCount; -- (void)setLastUploadSettings:(nullable MPUploadSettings *)lastUploadSettings; -- (nullable MPUploadSettings *)lastUploadSettings; - -+ (NSString *_Nullable)stringFromDeviceToken:(NSData *_Nonnull)deviceToken; -+ (nullable MPResponseConfig *)restore; -+ (void)deleteConfig; -+ (BOOL)isOlderThanConfigMaxAgeSeconds; - -@end diff --git a/mParticle-Apple-SDK/Utils/MPIUserDefaults.m b/mParticle-Apple-SDK/Utils/MPIUserDefaults.m deleted file mode 100644 index ba66b876e..000000000 --- a/mParticle-Apple-SDK/Utils/MPIUserDefaults.m +++ /dev/null @@ -1,531 +0,0 @@ -#import "MPIUserDefaults.h" -#import "MPPersistenceController.h" -#import "MPIConstants.h" -#import "MPILogger.h" -#import "mParticle.h" -#import "MPKitConfiguration.h" -#import "MPKitContainer.h" -#import "MParticleSwift.h" -#import "MPUpload.h" - -@interface MParticle () - -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; -@property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; -@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; - -@end - -static MPIUserDefaults *standardUserDefaults = nil; -static NSString * sharedGroupID = nil; - -NSString *const kitFileExtension = @"eks"; - -static NSString *const NSUserDefaultsPrefix = @"mParticle::"; - -@implementation MPIUserDefaults - -#pragma mark Private methods -- (NSArray *)userSpecificKeys { - NSArray *userSpecificKeys = @[ - @"lud", /* kMPAppLastUseDateKey */ - @"lc", /* kMPAppLaunchCountKey */ - @"lcu", /* kMPAppLaunchCountSinceUpgradeKey */ - @"ua", /* kMPUserAttributeKey */ - @"ui", /* kMPUserIdentityArrayKey */ - @"ck", /* kMPRemoteConfigCookiesKey */ - @"ltv", /* kMPLifeTimeValueKey */ - @"is_ephemeral", /* kMPIsEphemeralKey */ - @"last_date_used", /* kMPLastIdentifiedDate */ - @"consent_state", /* kMPConsentStateKey */ - @"fsu", /* kMPFirstSeenUser */ - @"lsu" /* kMPLastSeenUser */ - ]; - return userSpecificKeys; -} - -- (NSArray *)extensionExcludedKeys { - NSArray *extensionExcludedKeys = @[ - ]; - return extensionExcludedKeys; -} - -- (NSString *)globalKeyForKey:(NSString *)key { - NSString *globalKey = [NSString stringWithFormat:@"%@%@", NSUserDefaultsPrefix, key]; - return globalKey; -} - -- (NSString *)userKeyForKey:(NSString *)key userId:(NSNumber *)userId { - NSString *userKey = [NSString stringWithFormat:@"%@%@::%@", NSUserDefaultsPrefix, userId, key]; - return userKey; -} - -- (NSArray *)userIDsInUserDefaults { - NSArray *keyArray = [[[self customUserDefaults] dictionaryRepresentation] allKeys]; - - NSMutableSet *uniqueUserIDs = [[NSMutableSet alloc] init]; - for (NSString *key in keyArray) { - if ([[self customUserDefaults] objectForKey:key] != nil) { - NSArray *keyComponents = [key componentsSeparatedByString:@"::"]; - if (keyComponents.count == 3) { - NSNumber *userID = [NSNumber numberWithLongLong:[(NSString *)keyComponents[1] longLongValue]]; - [uniqueUserIDs addObject:userID]; - } - } - } - - return [uniqueUserIDs allObjects]; -} - -- (BOOL)isUserSpecificKey:(NSString *)keyName { - NSArray *userSpecificKeys = [self userSpecificKeys]; - - if ([userSpecificKeys containsObject:keyName]) { - return YES; - } - else { - return NO; - } -} - -- (NSString *)prefixedKey:(NSString *)keyName userId:(NSNumber *)userId { - NSString *prefixedKey = nil; - if (![self isUserSpecificKey:keyName]) { - prefixedKey = [self globalKeyForKey:keyName]; - return prefixedKey; - } - else { - NSString *prefixedKey = [self userKeyForKey:keyName userId:userId]; - return prefixedKey; - } -} - -- (NSUserDefaults *)customUserDefaults { - if (sharedGroupID) { - // Create and share access to an NSUserDefaults object - return [[NSUserDefaults alloc] initWithSuiteName: sharedGroupID]; - } else { - return [NSUserDefaults standardUserDefaults]; - } -} - -#pragma mark Public class methods -+ (nonnull instancetype)standardUserDefaults { - static dispatch_once_t predicate; - - dispatch_once(&predicate, ^{ - standardUserDefaults = [[MPIUserDefaults alloc] init]; - }); - - return standardUserDefaults; -} - -#pragma mark Public methods -- (id)mpObjectForKey:(NSString *)key userId:(NSNumber *)userId { - NSString *prefixedKey = [self prefixedKey:key userId:userId]; - - // If the shared key is set but that attribute hasn't been set in the shared user this defaults to getting the info for standard user info - id mpObject = [[self customUserDefaults] objectForKey:prefixedKey]; - if (mpObject) { - return mpObject; - } else { - return [[NSUserDefaults standardUserDefaults] objectForKey:prefixedKey]; - } -} - -- (void)setMPObject:(id)value forKey:(NSString *)key userId:(nonnull NSNumber *)userId { - NSString *prefixedKey = [self prefixedKey:key userId:userId]; - - [[NSUserDefaults standardUserDefaults] setObject:value forKey:prefixedKey]; - if (sharedGroupID && ![self.extensionExcludedKeys containsObject:key]) { - [[[NSUserDefaults alloc] initWithSuiteName: sharedGroupID] setObject:value forKey:prefixedKey]; - } -} - -- (void)removeMPObjectForKey:(NSString *)key userId:(nonnull NSNumber *)userId { - NSString *prefixedKey = [self prefixedKey:key userId:userId]; - - [[NSUserDefaults standardUserDefaults] removeObjectForKey:prefixedKey]; - if (sharedGroupID) { - [[[NSUserDefaults alloc] initWithSuiteName: sharedGroupID] removeObjectForKey:prefixedKey]; - } -} - -- (void)removeMPObjectForKey:(NSString *)key { - [self removeMPObjectForKey:key userId:[MPPersistenceController mpId]]; -} - -- (void)synchronize { - [[NSUserDefaults standardUserDefaults] synchronize]; - if (sharedGroupID) { - [[[NSUserDefaults alloc] initWithSuiteName: sharedGroupID] synchronize]; - } -} - -- (void)migrateUserKeysWithUserId:(NSNumber *)userId { - NSArray *userSpecificKeys = [self userSpecificKeys]; - NSUserDefaults *userDefaults = [self customUserDefaults]; - - [userSpecificKeys enumerateObjectsUsingBlock:^(NSString * _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) { - NSString *globalKey = [self globalKeyForKey:key]; - NSString *userKey = [self userKeyForKey:key userId:userId]; - id value = [userDefaults objectForKey:globalKey]; - [userDefaults setObject:value forKey:userKey]; - [userDefaults removeObjectForKey:globalKey]; - }]; - [userDefaults synchronize]; -} - -- (void)migrateFirstLastSeenUsers { - NSNumber *globalFirstSeenDateMs = [self mpObjectForKey:@"ict" /* kMPAppInitialLaunchTimeKey */ userId:[MPPersistenceController mpId]]; - NSNumber *globalLastSeenDateMs = @([NSDate date].timeIntervalSince1970 * 1000); - NSArray *users = [MParticle sharedInstance].identity.getAllUsers; - for (MParticleUser *user in users) { - [self setMPObject:globalFirstSeenDateMs forKey:kMPFirstSeenUser userId:user.userId]; - [self setMPObject:globalLastSeenDateMs forKey:kMPLastSeenUser userId:user.userId]; - } -} - --(void)setSharedGroupIdentifier:(NSString *)groupIdentifier { - NSString *storedGroupID = [self mpObjectForKey:kMPUserIdentitySharedGroupIdentifier userId:[MPPersistenceController mpId]]; - sharedGroupID = groupIdentifier; - - if ([sharedGroupID isEqualToString: storedGroupID] || (!storedGroupID && !sharedGroupID)) { - // Do nothing, we only want to update NSUserDefaults on a change - } else if (sharedGroupID != nil && ![sharedGroupID isEqualToString:@""]) { - [self migrateToSharedGroupIdentifier:sharedGroupID]; - } else { - [self migrateFromSharedGroupIdentifier]; - } -} - -- (void)migrateToSharedGroupIdentifier:(NSString *)groupIdentifier { - //Set up our identities to be shared between the main app and its extensions - NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; - NSUserDefaults *groupUserDefaults = [[NSUserDefaults alloc] initWithSuiteName: groupIdentifier]; - - NSString *prefixedKey = [self prefixedKey:kMPUserIdentitySharedGroupIdentifier userId:[MPPersistenceController mpId]]; - [standardUserDefaults setObject:groupIdentifier forKey:prefixedKey]; - [groupUserDefaults setObject:groupIdentifier forKey:prefixedKey]; - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@", NSUserDefaultsPrefix]; - NSArray *mParticleKeys = [[[standardUserDefaults dictionaryRepresentation] allKeys] filteredArrayUsingPredicate:predicate]; - - for (NSString *key in mParticleKeys) { - if (![self.extensionExcludedKeys containsObject:key]) { - [groupUserDefaults setObject:[standardUserDefaults objectForKey:key] forKey:key]; - } - } -} - -- (void)migrateFromSharedGroupIdentifier { - //Revert to the original way of storing our user identity info - NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; - NSUserDefaults *groupUserDefaults = [[NSUserDefaults alloc] initWithSuiteName: self[kMPUserIdentitySharedGroupIdentifier]]; - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@", NSUserDefaultsPrefix]; - NSArray *mParticleGroupKeys = [[[groupUserDefaults dictionaryRepresentation] allKeys] filteredArrayUsingPredicate:predicate]; - - for (NSString *key in mParticleGroupKeys) { - [groupUserDefaults removeObjectForKey:key]; - } - - NSString *prefixedKey = [self prefixedKey:kMPUserIdentitySharedGroupIdentifier userId:[MPPersistenceController mpId]]; - [groupUserDefaults removeObjectForKey:prefixedKey]; - [standardUserDefaults removeObjectForKey:prefixedKey]; -} - -- (NSDictionary *)getConfiguration { - NSNumber *userID = [[[MParticle sharedInstance] identity] currentUser].userId; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - - if (![[NSUserDefaults standardUserDefaults] objectForKey:kMResponseConfigurationMigrationKey]) { - [self migrateConfiguration]; - } - - NSData *configurationData = [userDefaults mpObjectForKey:kMResponseConfigurationKey userId:userID]; - if (MPIsNull(configurationData)) { - return nil; - } - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - NSDictionary *configuration = nil; - @try { - configuration = [NSKeyedUnarchiver unarchiveObjectWithData:configurationData]; - } @catch (NSException *e) { - MPILogError(@"Got an exception trying to unarchive configuration: %@", e); - return nil; - } -#pragma clang diagnostic pop - - if (![configuration isKindOfClass:[NSDictionary class]]) { - return nil; - } - - return configuration; -} - -- (NSArray *)getKitConfigurations { - NSArray *configuration = [self getConfiguration][kMPRemoteConfigKitsKey]; - return configuration; -} - -- (void)setConfiguration:(nonnull NSDictionary *)responseConfiguration eTag:(nonnull NSString *)eTag requestTimestamp:(NSTimeInterval)requestTimestamp currentAge:(nonnull NSString *)currentAge maxAge:(nullable NSNumber *)maxAge { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - - if (!responseConfiguration) { - MPILogDebug(@"Set Configuration Failed \nConfiguration: %@", responseConfiguration); - - return; - } - - NSData *configuration = nil; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - @try { - configuration = [NSKeyedArchiver archivedDataWithRootObject:responseConfiguration]; - } @catch (NSException *e) { - MPILogError(@"Got an exception trying to archive configuration: %@", e); - return; - } -#pragma clang diagnostic pop - - NSNumber *userID = [[[MParticle sharedInstance] identity] currentUser].userId; - - [userDefaults setMPObject:eTag forKey:kMPHTTPETagHeaderKey userId:userID]; - [userDefaults setMPObject:configuration forKey:kMResponseConfigurationKey userId:userID]; - userDefaults[kMPConfigProvisionedTimestampKey] = @(requestTimestamp - [currentAge integerValue]); - userDefaults[kMPConfigMaxAgeHeaderKey] = maxAge; - userDefaults[kMPConfigParameters] = [self currentConfigurationParameters]; -} - -- (void)migrateConfiguration { - NSNumber *userID = [[[MParticle sharedInstance] identity] currentUser].userId; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSString *eTag = [userDefaults mpObjectForKey:kMPHTTPETagHeaderKey userId:userID]; - - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *stateMachineDirectoryPath = STATE_MACHINE_DIRECTORY_PATH; - NSString *configurationPath = [stateMachineDirectoryPath stringByAppendingPathComponent:@"RequestConfig.cfg"]; - - NSDictionary *configuration = [userDefaults mpObjectForKey:kMResponseConfigurationKey userId:userID]; - - if ([fileManager fileExistsAtPath:configurationPath]) { - [fileManager removeItemAtPath:configurationPath error:nil]; - [self deleteConfiguration]; - MPILogDebug(@"Configuration Migration Complete"); - } else if ((eTag && !configuration) || (!eTag && configuration)) { - [self deleteConfiguration]; - MPILogDebug(@"Configuration Migration Complete"); - } - - [[NSUserDefaults standardUserDefaults] setObject:@1 forKey:kMResponseConfigurationMigrationKey]; -} - -- (void)deleteConfiguration { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - - [userDefaults removeMPObjectForKey:kMResponseConfigurationKey]; - [userDefaults removeMPObjectForKey:kMPHTTPETagHeaderKey]; - - userDefaults[kMPConfigProvisionedTimestampKey] = nil; - userDefaults[kMPConfigMaxAgeHeaderKey] = nil; - userDefaults[kMPConfigParameters] = nil; - - MPILogDebug(@"Configuration Deleted"); -} - -- (void)resetDefaults { - NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; - NSDictionary * dict = [defs dictionaryRepresentation]; - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@", NSUserDefaultsPrefix]; - NSArray *mParticleKeys = [dict.allKeys filteredArrayUsingPredicate:predicate]; - - if (sharedGroupID) { - [self setSharedGroupIdentifier:nil]; - } - - for (id key in mParticleKeys) { - [defs removeObjectForKey:key]; - } - - [defs synchronize]; -} - -- (BOOL)isExistingUserId:(NSNumber *)userId { - NSDate *dateLastIdentified = [self mpObjectForKey:kMPLastIdentifiedDate userId:userId]; - if (dateLastIdentified != nil) { - return true; - } - - return false; -} - -- (BOOL)isConfigurationExpired { - BOOL isConfigurationExpired = YES; - - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSNumber *configProvisioned = userDefaults[kMPConfigProvisionedTimestampKey]; - NSNumber *maxAge = userDefaults[kMPConfigMaxAgeHeaderKey]; - - if (configProvisioned != nil) { - NSTimeInterval intervalConfigProvisioned = [configProvisioned doubleValue]; - NSTimeInterval intervalNow = [[NSDate date] timeIntervalSince1970]; - NSTimeInterval delta = intervalNow - intervalConfigProvisioned; - NSTimeInterval expirationAge = (maxAge != nil) ? MIN([maxAge doubleValue], CONFIG_REQUESTS_MAX_EXPIRATION_AGE) : CONFIG_REQUESTS_DEFAULT_EXPIRATION_AGE; - isConfigurationExpired = delta > expirationAge; - } - - return isConfigurationExpired; -} - -- (BOOL)isConfigurationParametersOutdated { - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSString *oldParameters = userDefaults[kMPConfigParameters]; - NSString *currentParameters = [self currentConfigurationParameters]; - - if (currentParameters != nil && oldParameters != nil) { - if ([currentParameters isEqualToString:oldParameters]) { - return NO; - } - } - - return YES; -} - -- (NSString *)currentConfigurationParameters { - NSMutableString *configString = [NSMutableString string]; - - if (MParticle.sharedInstance.version != nil) { - [configString appendFormat:@"SDK Version: %@\n", MParticle.sharedInstance.version]; - } - - MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance].stateMachine; - - if (stateMachine.apiKey != nil) { - [configString appendFormat:@"API Key: %@\n", stateMachine.apiKey]; - } - - NSMutableString *supportedKitsString = [NSMutableString string]; - NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" - ascending: YES]; - NSArray *supportedKits = [[[MParticle sharedInstance].kitContainer_PRIVATE supportedKits] sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]]; - if (supportedKits != nil) { - for (NSNumber *kitID in supportedKits) { - [supportedKitsString appendFormat:@"%@\n", kitID]; - } - } - [configString appendFormat:@"Supported Kits: \n%@\n", supportedKitsString]; - - NSNumber *environment = [NSNumber numberWithInt:(int)[MPStateMachine_PRIVATE environment]]; - [configString appendFormat:@"Environment: %@\n", environment]; - - return [MPIHasher hashString:configString]; -} - -- (void)setSideloadedKitsCount:(NSUInteger)sideloadedKitsCount { - [[NSUserDefaults standardUserDefaults] setObject:@(sideloadedKitsCount) forKey:MPSideloadedKitsCountUserDefaultsKey]; -} - -- (NSUInteger)sideloadedKitsCount { - return [[[NSUserDefaults standardUserDefaults] objectForKey:MPSideloadedKitsCountUserDefaultsKey] intValue]; -} - -- (void)setLastUploadSettings:(nullable MPUploadSettings *)lastUploadSettings { - if (!lastUploadSettings) { - [[NSUserDefaults standardUserDefaults] removeObjectForKey:kMPLastUploadSettingsUserDefaultsKey]; - return; - } - - @try { - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:lastUploadSettings]; - [[NSUserDefaults standardUserDefaults] setObject:data forKey:kMPLastUploadSettingsUserDefaultsKey]; - } @catch(NSException *exception) { - MPILogError(@"Error serializing last upload settings: %@: %@", exception.name, exception.reason); - [self setLastUploadSettings:nil]; - } -} - -- (nullable MPUploadSettings *)lastUploadSettings { - NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kMPLastUploadSettingsUserDefaultsKey]; - if (data) { - @try { - MPUploadSettings *uploadSettings = [NSKeyedUnarchiver unarchiveObjectWithData:data]; - return uploadSettings; - } @catch(NSException *exception) { - MPILogError(@"Error deserializing last upload settings: %@: %@", exception.name, exception.reason); - [self setLastUploadSettings:nil]; - } - } - return nil; -} - -#pragma mark Objective-C Literals -- (id)objectForKeyedSubscript:(NSString *const)key { - if ([key isEqualToString:@"mpid"]) { - return [self mpObjectForKey:key userId:@0]; - } - return [self mpObjectForKey:key userId:[MPPersistenceController mpId]]; -} - -- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key { - if (obj) { - if ([key isEqualToString:@"mpid"]) { - [self setMPObject:obj forKey:key userId:@0]; - } else { - [self setMPObject:obj forKey:key userId:[MPPersistenceController mpId]]; - } - } else { - [self removeMPObjectForKey:key userId:[MPPersistenceController mpId]]; - } -} - -+ (NSString *)stringFromDeviceToken:(NSData *)deviceToken { - NSUInteger length = deviceToken.length; - if (deviceToken == nil || length == 0) { - return nil; - } - const unsigned char *buffer = deviceToken.bytes; - NSMutableString *hexString = [NSMutableString stringWithCapacity:(length * 2)]; - for (int i = 0; i < length; ++i) { - [hexString appendFormat:@"%02x", buffer[i]]; - } - return [hexString copy]; -} - -+ (nullable MPResponseConfig *)restore { - NSDictionary *configuration = [[MPIUserDefaults standardUserDefaults] getConfiguration]; - MPResponseConfig *responseConfig = [[MPResponseConfig alloc] initWithConfiguration:configuration dataReceivedFromServer:NO stateMachine:MParticle.sharedInstance.stateMachine backendController:MParticle.sharedInstance.backendController]; - - return responseConfig; -} - -+ (void)deleteConfig { - [[MPIUserDefaults standardUserDefaults] deleteConfiguration]; -} - -+ (BOOL)isOlderThanConfigMaxAgeSeconds { - BOOL shouldConfigurationBeDeleted = NO; - - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; - NSNumber *configProvisioned = userDefaults[kMPConfigProvisionedTimestampKey]; - NSNumber *maxAgeSeconds = [[MParticle sharedInstance] configMaxAgeSeconds]; - - if (configProvisioned != nil && maxAgeSeconds != nil && [maxAgeSeconds doubleValue] > 0) { - NSTimeInterval intervalConfigProvisioned = [configProvisioned doubleValue]; - NSTimeInterval intervalNow = [[NSDate date] timeIntervalSince1970]; - NSTimeInterval delta = intervalNow - intervalConfigProvisioned; - shouldConfigurationBeDeleted = delta > [maxAgeSeconds doubleValue]; - } - - if (shouldConfigurationBeDeleted) { - [[MPIUserDefaults standardUserDefaults] deleteConfiguration]; - } - - return shouldConfigurationBeDeleted; -} - - -@end diff --git a/mParticle-Apple-SDK/Utils/MPMessageBuilder.m b/mParticle-Apple-SDK/Utils/MPMessageBuilder.m index 6465e6634..8450e8001 100644 --- a/mParticle-Apple-SDK/Utils/MPMessageBuilder.m +++ b/mParticle-Apple-SDK/Utils/MPMessageBuilder.m @@ -291,7 +291,7 @@ - (MPMessage *)build { _messageDictionary[kMPMessageTypeKey] = _messageType; _messageDictionary[kMPMessageIdKey] = _uuid ?: [[NSUUID UUID] UUIDString]; - NSNumber *userId = _session.userId.integerValue ? _session.userId : [MPPersistenceController mpId]; + NSNumber *userId = _session.userId.integerValue ? _session.userId : [MPPersistenceController_PRIVATE mpId]; MPMessage *message = [[MPMessage alloc] initWithSession:_session messageType:_messageType diff --git a/mParticle-Apple-SDK/Utils/MPUploadBuilder.m b/mParticle-Apple-SDK/Utils/MPUploadBuilder.m index 9bcb1939c..8eaf14638 100644 --- a/mParticle-Apple-SDK/Utils/MPUploadBuilder.m +++ b/mParticle-Apple-SDK/Utils/MPUploadBuilder.m @@ -4,7 +4,6 @@ #import "MPUpload.h" #import "MPStateMachine.h" #import "MPIConstants.h" -#import "MPIUserDefaults.h" #import "MPPersistenceController.h" #import "MPCustomModule.h" #import "MPConsumerInfo.h" @@ -16,11 +15,13 @@ #import "MPConsentSerialization.h" #import "mParticle.h" #import "MPILogger.h" +#import "MParticleSwift.h" @interface MParticle () -@property (nonatomic, strong, readonly) MPPersistenceController *persistenceController; +@property (nonatomic, strong, readonly) MPPersistenceController_PRIVATE *persistenceController; @property (nonatomic, strong, readonly) MPStateMachine_PRIVATE *stateMachine; +@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController; @property (nonatomic, strong, nonnull) MParticleOptions *options; @end @@ -67,7 +68,7 @@ - (nonnull instancetype)initWithMpid:(nonnull NSNumber *)mpid sessionId:(nullabl }]; NSNumber *ltv; - MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults]; + MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; ltv = [userDefaults mpObjectForKey:kMPLifeTimeValueKey userId:mpid]; if (ltv == nil) { ltv = @0; @@ -188,7 +189,7 @@ - (void)build:(void (^)(MPUpload *upload))completionHandler { _uploadDictionary[kMPDeviceApplicationStampKey] = deviceApplicationStamp; } - MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController; + MPPersistenceController_PRIVATE *persistence = [MParticle sharedInstance].persistenceController; NSArray *forwardRecords = [persistence fetchForwardRecords]; NSMutableArray *forwardRecordsIds = nil; @@ -221,7 +222,7 @@ - (void)build:(void (^)(MPUpload *upload))completionHandler { _uploadDictionary[MPIntegrationAttributesKey] = integrationAttributesDictionary; } - MPConsentState *consentState = [MPPersistenceController consentStateForMpid:_uploadDictionary[kMPRemoteConfigMPIDKey]]; + MPConsentState *consentState = [MPPersistenceController_PRIVATE consentStateForMpid:_uploadDictionary[kMPRemoteConfigMPIDKey]]; if (consentState) { NSDictionary *consentStateDictionary = [MPConsentSerialization serverDictionaryFromConsentState:consentState]; if (consentStateDictionary) { diff --git a/mParticle-Apple-SDK/Utils/MPUploadSettings.swift b/mParticle-Apple-SDK/Utils/MPUploadSettings.swift new file mode 100644 index 000000000..72790e742 --- /dev/null +++ b/mParticle-Apple-SDK/Utils/MPUploadSettings.swift @@ -0,0 +1,104 @@ +// +// MPUploadSettings.swift +// mParticle-Apple-SDK +// +// Created by Brandon Stalnaker on 1/22/25. +// +private let kApiKey = "apiKey" +private let kSecret = "secret" +private let kEventsHost = "eventsHost" +private let kEventsTrackingHost = "eventsTrackingHost" +private let kOverridesEventsSubdirectory: String = "overridesEventsSubdirectory" +private let kAliasHost = "aliasHost" +private let kAliasTrackingHost = "aliasTrackingHost" +private let kOverridesAliasSubdirectory = "overridesAliasSubdirectory" +private let kEventsOnly = "eventsOnly" + +@objc public class MPUploadSettings: NSObject, NSCopying, NSSecureCoding { + @objc public var apiKey: String + @objc public var secret: String + @objc public var eventsHost: String? + @objc public var eventsTrackingHost: String? + @objc public var overridesEventsSubdirectory: Bool = false + @objc public var aliasHost: String? + @objc public var aliasTrackingHost: String? + @objc public var overridesAliasSubdirectory: Bool = false + @objc public var eventsOnly: Bool = false + + @objc public override init() { + self.apiKey = "" + self.secret = "" + super.init() + } + + public func copy(with zone: NSZone? = nil) -> Any { + return MPUploadSettings(apiKey: self.apiKey, + secret: self.secret, + eventsHost: self.eventsHost, + eventsTrackingHost: self.eventsTrackingHost, + overridesEventsSubdirectory: self.overridesEventsSubdirectory, + aliasHost: self.aliasHost, + aliasTrackingHost: self.aliasTrackingHost, + overridesAliasSubdirectory: self.overridesAliasSubdirectory, + eventsOnly: self.eventsOnly) + } + + public static var supportsSecureCoding: Bool = true + + public func encode(with coder: NSCoder) { + coder.encode(apiKey, forKey: kApiKey) + coder.encode(secret, forKey: kSecret) + coder.encode(eventsHost, forKey: kEventsHost) + coder.encode(eventsTrackingHost, forKey: kEventsTrackingHost) + coder.encode(overridesEventsSubdirectory, forKey: kOverridesEventsSubdirectory) + coder.encode(aliasHost, forKey: kAliasHost) + coder.encode(aliasTrackingHost, forKey: kAliasTrackingHost) + coder.encode(overridesAliasSubdirectory, forKey: kOverridesAliasSubdirectory) + coder.encode(eventsOnly, forKey: kEventsOnly) + } + + @objc public required init?(coder: NSCoder) { + self.apiKey = coder.decodeObject(forKey: kApiKey) as? String ?? "" + self.secret = coder.decodeObject(forKey: kSecret) as? String ?? "" + self.eventsHost = coder.decodeObject(forKey: kEventsHost) as? String + self.eventsTrackingHost = coder.decodeObject(forKey: kEventsTrackingHost) as? String + self.overridesEventsSubdirectory = coder.decodeBool(forKey: kOverridesEventsSubdirectory) + self.aliasHost = coder.decodeObject(forKey: kAliasHost) as? String + self.aliasTrackingHost = coder.decodeObject(forKey: kAliasTrackingHost) as? String + self.overridesAliasSubdirectory = coder.decodeBool(forKey: kOverridesAliasSubdirectory) + self.eventsOnly = coder.decodeBool(forKey: kEventsOnly) + + } + + @objc public class func currentUploadSettings(stateMachine: MPStateMachine_PRIVATE, networkOptions: MPNetworkOptions) -> MPUploadSettings { + return MPUploadSettings(apiKey: stateMachine.apiKey, secret: stateMachine.secret, networkOptions: networkOptions) + } + + @objc public init(apiKey: String, secret: String, eventsHost: String? = nil, eventsTrackingHost: String? = nil, overridesEventsSubdirectory: Bool = false, aliasHost: String? = nil, aliasTrackingHost: String? = nil, overridesAliasSubdirectory: Bool = false, eventsOnly: Bool = false) { + self.apiKey = apiKey + self.secret = secret + self.eventsHost = eventsHost + self.eventsTrackingHost = eventsTrackingHost + self.overridesEventsSubdirectory = overridesEventsSubdirectory + self.aliasHost = aliasHost + self.aliasTrackingHost = aliasTrackingHost + self.overridesAliasSubdirectory = overridesAliasSubdirectory + self.eventsOnly = eventsOnly + + super.init() + } + + @objc public init(apiKey: String, secret: String, networkOptions: MPNetworkOptions) { + self.apiKey = apiKey + self.secret = secret + self.eventsHost = networkOptions.eventsHost + self.eventsTrackingHost = networkOptions.eventsTrackingHost + self.overridesEventsSubdirectory = networkOptions.overridesEventsSubdirectory + self.aliasHost = networkOptions.aliasHost + self.aliasTrackingHost = networkOptions.aliasTrackingHost + self.overridesAliasSubdirectory = networkOptions.overridesAliasSubdirectory + self.eventsOnly = networkOptions.eventsOnly + + super.init() + } +} diff --git a/mParticle-Apple-SDK/Utils/MPUserDefaults.swift b/mParticle-Apple-SDK/Utils/MPUserDefaults.swift new file mode 100644 index 000000000..c09257404 --- /dev/null +++ b/mParticle-Apple-SDK/Utils/MPUserDefaults.swift @@ -0,0 +1,397 @@ +// +// MPUserDefaults.swift +// mParticle-Apple-SDK +// +// Created by Brandon Stalnaker on 1/10/25. +// + +import Foundation +private var userDefaults: MPUserDefaults? +private var sharedGroupID: String? +private let NSUserDefaultsPrefix = "mParticle::" +private let userSpecificKeys = ["lud", /* kMPAppLastUseDateKey */ + "lc", /* kMPAppLaunchCountKey */ + "lcu", /* kMPAppLaunchCountSinceUpgradeKey */ + "ua", /* kMPUserAttributeKey */ + "ui", /* kMPUserIdentityArrayKey */ + "ck", /* kMPRemoteConfigCookiesKey */ + "ltv", /* kMPLifeTimeValueKey */ + "is_ephemeral", /* kMPIsEphemeralKey */ + "last_date_used", /* kMPLastIdentifiedDate */ + "consent_state", /* kMPConsentStateKey */ + "fsu", /* kMPFirstSeenUser */ + "lsu" /* kMPLastSeenUser */ + ] +private let kMPUserIdentitySharedGroupIdentifier = "sgi" +private let kMResponseConfigurationKey = "responseConfiguration" +private let kMResponseConfigurationMigrationKey = "responseConfigurationMigrated" + +@objc public class MPUserDefaults : NSObject { + private var stateMachine: MPStateMachine_PRIVATE? + private var backendController: MPBackendController_PRIVATE? + private var identity: MPIdentityApi? + + required public init(stateMachine: MPStateMachine_PRIVATE, backendController: MPBackendController_PRIVATE, identity: MPIdentityApi) { + self.stateMachine = stateMachine + self.backendController = backendController + self.identity = identity + super.init() + } + + @objc public class func standardUserDefaults(stateMachine: MPStateMachine_PRIVATE, backendController: MPBackendController_PRIVATE, identity: MPIdentityApi) -> MPUserDefaults { + if userDefaults == nil { + userDefaults = self.init(stateMachine: stateMachine, backendController: backendController, identity: identity) + } + + return userDefaults! + } + + @objc public func mpObject(forKey key: String, userId: NSNumber) -> Any? { + let prefixedKey = MPUserDefaults.prefixedKey(key, userId: userId) + + var mpObject = self.customUserDefaults().object(forKey: prefixedKey) + if mpObject == nil { + mpObject = UserDefaults.standard.object(forKey: prefixedKey) + } + return mpObject + } + + @objc public func setMPObject(_ value: Any?, forKey key: String, userId: NSNumber) { + let prefixedKey = MPUserDefaults.prefixedKey(key, userId: userId) + + UserDefaults.standard.set(value, forKey: prefixedKey) + if sharedGroupID != nil { + UserDefaults(suiteName: sharedGroupID)?.set(value, forKey: prefixedKey) + } + } + + @objc public func removeMPObject(forKey key: String, userId: NSNumber) { + let prefixedKey = MPUserDefaults.prefixedKey(key, userId: userId) + + UserDefaults.standard.removeObject(forKey: prefixedKey) + if sharedGroupID != nil { + UserDefaults(suiteName: sharedGroupID)?.removeObject(forKey: prefixedKey) + } + } + + @objc public func removeMPObject(forKey key: String) { + self.removeMPObject(forKey: key, userId: MPPersistenceController_PRIVATE.mpId()) + } + + @objc public subscript(key: String) -> Any? { + get { + if key == "mpid" { + return self.mpObject(forKey: key, userId: 0) + } + return self.mpObject(forKey: key, userId: MPPersistenceController_PRIVATE.mpId()) + } + set { + if let obj = newValue { + if key == "mpid" { + self.setMPObject(obj, forKey: key, userId: 0) + } else { + self.setMPObject(obj, forKey: key, userId: MPPersistenceController_PRIVATE.mpId()) + } + } else { + self.removeMPObject(forKey: key, userId: MPPersistenceController_PRIVATE.mpId()) + } + } + } + + @objc public func synchronize() { + UserDefaults.standard.synchronize() + if sharedGroupID != nil { + UserDefaults(suiteName: sharedGroupID)?.synchronize() + } + } + + @objc public func migrateUserKeys(withUserId userId: NSNumber) { + userSpecificKeys.forEach { key in + let globalKey = MPUserDefaults.globalKeyForKey(key) + let userKey = MPUserDefaults.userKeyForKey(key, userId: userId) + guard let value = UserDefaults.standard.object(forKey: globalKey) else { return } + self.customUserDefaults().set(value, forKey: userKey) + } + + self.synchronize() + } + + @objc public func migrateFirstLastSeenUsers() { + let globalFirstSeenDateMs = self.mpObject(forKey: Miscellaneous.kMPAppInitialLaunchTimeKey, userId: MPPersistenceController_PRIVATE.mpId()) + let globalLastSeenDateMs = NSNumber(value: Date().timeIntervalSince1970 * 1000) + let users: [MParticleUser] = self.identity?.getAllUsers() ?? [] + for user in users { + self.setMPObject(globalFirstSeenDateMs, forKey: Miscellaneous.kMPFirstSeenUser, userId: user.userId) + self.setMPObject(globalLastSeenDateMs, forKey: Miscellaneous.kMPLastSeenUser, userId: user.userId) + } + } + + @objc public func setSharedGroupIdentifier(_ groupIdentifier: String?) { + let storedGroupID = self.mpObject(forKey: kMPUserIdentitySharedGroupIdentifier, userId: MPPersistenceController_PRIVATE.mpId()) as? String + + if storedGroupID == groupIdentifier { + + } else if let groupIdentifier = groupIdentifier, !groupIdentifier.isEmpty { + self.migrateToSharedGroupIdentifier(groupIdentifier: groupIdentifier) + } else { + self.migrateFromSharedGroupIdentifier() + } + } + + @objc public func migrateToSharedGroupIdentifier(groupIdentifier: String) { + let standardUserDefaults = UserDefaults.standard + let groupUserDefaults = UserDefaults(suiteName: groupIdentifier) + + let prefixedKey = + MPUserDefaults.prefixedKey(kMPUserIdentitySharedGroupIdentifier, userId: MPPersistenceController_PRIVATE.mpId()) + standardUserDefaults.set(groupIdentifier, forKey: prefixedKey) + groupUserDefaults?.set(groupIdentifier, forKey: prefixedKey) + + let predicate = NSPredicate(format: "SELF CONTAINS %@", NSUserDefaultsPrefix) + let mParticleKeys = UserDefaults.standard.dictionaryRepresentation().keys.filter { predicate.evaluate(with: $0) } + + for key in mParticleKeys { + groupUserDefaults?.set(standardUserDefaults.object(forKey: key), forKey: key) + } + } + + @objc public func migrateFromSharedGroupIdentifier() { + let standardUserDefaults = UserDefaults.standard + let groupUserDefaults = UserDefaults(suiteName: sharedGroupID) + + let predicate = NSPredicate(format: "SELF CONTAINS %@", NSUserDefaultsPrefix) + let mParticleKeys = UserDefaults.standard.dictionaryRepresentation().keys.filter { predicate.evaluate(with: $0) } + + for key in mParticleKeys { + groupUserDefaults?.removeObject(forKey: key) + } + + let prefixedKey = + MPUserDefaults.prefixedKey(kMPUserIdentitySharedGroupIdentifier, userId: MPPersistenceController_PRIVATE.mpId()) + standardUserDefaults.removeObject(forKey: prefixedKey) + groupUserDefaults?.removeObject(forKey: prefixedKey) + } + + @objc public func getConfiguration() -> [AnyHashable : Any]? { + guard let userID = self.identity?.currentUser?.userId else {return nil} + + if UserDefaults.standard.object(forKey: kMResponseConfigurationMigrationKey) == nil { + migrateConfiguration() + } + + let configurationData = self.mpObject(forKey: kMResponseConfigurationKey, userId: userID) as? Data + guard let configurationData = configurationData else { return nil } + + let configuration = NSKeyedUnarchiver.unarchiveObject(with: configurationData) as? [AnyHashable : Any] + + return configuration + } + + @objc public func getKitConfigurations() -> [Any]? { + return self.getConfiguration()?[RemoteConfig.kMPRemoteConfigKitsKey] as? [Any] + } + + @objc public func setConfiguration(_ responseConfiguration: [AnyHashable : Any], eTag: String, requestTimestamp: TimeInterval, currentAge: TimeInterval, maxAge: NSNumber?) { + let configurationData = NSKeyedArchiver.archivedData(withRootObject: responseConfiguration) + let userID = self.identity?.currentUser?.userId ?? 0 + + self.setMPObject(eTag, forKey: Miscellaneous.kMPHTTPETagHeaderKey, userId: userID) + self.setMPObject(configurationData, forKey: kMResponseConfigurationKey, userId: userID) + self.setMPObject(requestTimestamp - currentAge, forKey: Miscellaneous.kMPConfigProvisionedTimestampKey, userId: userID) + self.setMPObject(maxAge, forKey: Miscellaneous.kMPConfigMaxAgeHeaderKey, userId: userID) + } + + @objc public func migrateConfiguration() { + guard let userID = self.identity?.currentUser?.userId else {return} + let eTag = self.mpObject(forKey: Miscellaneous.kMPHTTPETagHeaderKey, userId: userID) as? String + + let fileManager = FileManager.default + guard let cachesURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else { return } + let stateMachineURL = cachesURL.appendingPathComponent("StateMachine") + let configurationURL = stateMachineURL.appendingPathComponent("RequestConfig.cfg") + let configuration = self.mpObject(forKey: kMResponseConfigurationKey, userId: userID) + + if fileManager.fileExists(atPath: configurationURL.path) { + do { + try fileManager.removeItem(at: configurationURL) + } catch { + MPLog.error("Failed to remove old configuration file: \(error)") + } + self.deleteConfiguration() + MPLog.debug( "Configuration Migration Complete") + } else if (eTag != nil && configuration == nil) || (eTag == nil && configuration != nil) { + self.deleteConfiguration() + MPLog.debug( "Configuration Migration Complete") + } + + UserDefaults.standard.set(1, forKey: kMResponseConfigurationMigrationKey) + } + + @objc public func deleteConfiguration() { + self.removeMPObject(forKey: kMResponseConfigurationKey) + self.removeMPObject(forKey: Miscellaneous.kMPHTTPETagHeaderKey) + self.removeMPObject(forKey: Miscellaneous.kMPConfigProvisionedTimestampKey) + self.removeMPObject(forKey: Miscellaneous.kMPConfigMaxAgeHeaderKey) + self.removeMPObject(forKey: Miscellaneous.kMPConfigParameters) + + MPLog.debug( "Configuration Deleted") + } + + @objc public func resetDefaults() { + let dict = UserDefaults.standard.dictionaryRepresentation() + let predicate = NSPredicate(format: "SELF CONTAINS %@", NSUserDefaultsPrefix) + let mParticleKeys = dict.keys.filter { predicate.evaluate(with: $0) } + + if sharedGroupID != nil { + self.setSharedGroupIdentifier(nil) + } + + for key in mParticleKeys { + UserDefaults.standard.removeObject(forKey: key) + } + userDefaults = nil + + UserDefaults.standard.synchronize() + } + + @objc public func isExistingUserId(_ userId: NSNumber) -> Bool { + let dateLastIdentified = self.mpObject(forKey: Miscellaneous.kMPLastIdentifiedDate, userId: userId) + + return dateLastIdentified != nil + } + + @objc public func userIDsInUserDefaults() -> [NSNumber] { + let keyArray = self.customUserDefaults().dictionaryRepresentation().keys + + var uniqueUserIDs: [NSNumber] = [] + for key in keyArray { + if let _ = self.customUserDefaults().object(forKey: key) { + let keyComponents = key.components(separatedBy: "::") + if keyComponents.count == 3 { + let UserID = NSNumber(value: Int64(keyComponents[1]) ?? 0) + uniqueUserIDs.append(UserID) + } + } + } + + return uniqueUserIDs + } + + @objc public func isConfigurationExpired() -> Bool { + var isConfigurationExpired: Bool = true + + let configProvisioned = self.mpObject(forKey: Miscellaneous.kMPConfigProvisionedTimestampKey, userId: MPPersistenceController_PRIVATE.mpId()) as? NSNumber + let maxAge = self.mpObject(forKey: Miscellaneous.kMPConfigMaxAgeHeaderKey, userId: MPPersistenceController_PRIVATE.mpId()) + + if let configProvisioned = configProvisioned { + let intervalConfigProvisioned = configProvisioned.doubleValue + let intervalNow = Date().timeIntervalSince1970 + let delta = intervalNow - intervalConfigProvisioned + var expirationAge = Miscellaneous.CONFIG_REQUESTS_DEFAULT_EXPIRATION_AGE + if let maxAge = maxAge as? NSNumber { + expirationAge = min(maxAge.doubleValue, Miscellaneous.CONFIG_REQUESTS_MAX_EXPIRATION_AGE) + } + isConfigurationExpired = delta > expirationAge + } + + return isConfigurationExpired + } + + @objc public func setSideloadedKitsCount(_ sideloadedKitsCount: UInt) { + setMPObject(sideloadedKitsCount, forKey: Miscellaneous.MPSideloadedKitsCountUserDefaultsKey, userId: 0) + } + + @objc public func sideloadedKitsCount() -> UInt { + mpObject(forKey: Miscellaneous.MPSideloadedKitsCountUserDefaultsKey, userId: 0) as? UInt ?? 0 + } + + @objc public func setLastUploadSettings(_ lastUploadSettings: MPUploadSettings?) { + if let lastUploadSettings = lastUploadSettings { + let data = NSKeyedArchiver.archivedData(withRootObject: lastUploadSettings) + setMPObject(data, forKey: Miscellaneous.kMPLastUploadSettingsUserDefaultsKey, userId: 0) + } else { + removeMPObject(forKey: Miscellaneous.kMPLastUploadSettingsUserDefaultsKey, userId: 0) + } + } + + @objc public func lastUploadSettings() -> MPUploadSettings? { + let data = mpObject(forKey: Miscellaneous.kMPLastUploadSettingsUserDefaultsKey, userId: 0) as? Data + + if let data = data { + return NSKeyedUnarchiver.unarchiveObject(with: data) as? MPUploadSettings + } else { + return nil + } + } + + @objc public class func isOlderThanConfigMaxAgeSeconds() -> Bool { + var shouldConfigurationBeDeleted: Bool = false + + if let userDefaults = userDefaults { + let configProvisioned = userDefaults[Miscellaneous.kMPConfigProvisionedTimestampKey] as? NSNumber + let maxAgeSeconds = MParticle.sharedInstance().configMaxAgeSeconds + + if let configProvisioned = configProvisioned, let maxAgeSeconds = maxAgeSeconds, maxAgeSeconds.doubleValue > 0 { + let intervalConfigProvisioned: TimeInterval = configProvisioned.doubleValue + shouldConfigurationBeDeleted = (Date().timeIntervalSince1970 - intervalConfigProvisioned) > maxAgeSeconds.doubleValue + } + + if shouldConfigurationBeDeleted { + userDefaults.deleteConfiguration() + } + } + return shouldConfigurationBeDeleted + } + + @objc public class func stringFromDeviceToken(_ deviceToken: Data) -> String? { + if deviceToken.count == 0 { return nil } + + return deviceToken.map { String(format: "%02x", $0) }.joined() + } + + @objc public class func restore() -> MPResponseConfig? { + if let userDefaults = userDefaults { + if let configuration = userDefaults.getConfiguration(), let stateMachine = userDefaults.stateMachine, let backendController = userDefaults.backendController { + let responseConfig = MPResponseConfig(configuration: configuration, stateMachine: stateMachine, backendController: backendController) + + return responseConfig + } + } + + return nil + } + + @objc public class func deleteConfig() { + if let userDefaults = userDefaults { + userDefaults.deleteConfiguration() + } + } + + + // Private Methods + private class func globalKeyForKey(_ keyName: String) -> String { + return "\(NSUserDefaultsPrefix)\(keyName)" + } + + private class func userKeyForKey(_ keyName: String, userId: NSNumber) -> String { + return "\(NSUserDefaultsPrefix)\(userId)::\(keyName)" + } + + private class func prefixedKey(_ keyName: String, userId: NSNumber) -> String { + var prefixedKey: String? + if userSpecificKeys.contains(keyName) { + prefixedKey = userKeyForKey(keyName, userId: userId) + } else { + prefixedKey = globalKeyForKey(keyName) + } + return prefixedKey ?? "" + } + + private func customUserDefaults() -> UserDefaults { + if let sharedGroupID = sharedGroupID { + return UserDefaults(suiteName: sharedGroupID) ?? .standard + } else { + return .standard + } + } +} diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index 5b3c37879..990f2e360 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -10,9 +10,7 @@ #import "MPKitActivity.h" #import "MPKitFilter.h" #import "MPNetworkPerformance.h" -#import "MPPersistenceController.h" #import "MPSession.h" -#import "MPIUserDefaults.h" #import "MPIdentityApi.h" #import "MPDataPlanFilter.h" #import "MPUpload.h" @@ -51,7 +49,7 @@ @interface MParticle() 0) { + NSTimeInterval intervalConfigProvisioned = [configProvisioned doubleValue]; + NSTimeInterval intervalNow = [[NSDate date] timeIntervalSince1970]; + NSTimeInterval delta = intervalNow - intervalConfigProvisioned; + shouldConfigurationBeDeleted = delta > [maxAgeSeconds doubleValue]; + } + + if (shouldConfigurationBeDeleted) { + [userDefaults deleteConfiguration]; + } + + return shouldConfigurationBeDeleted; +} + @end