diff --git a/UnitTests/MPBackendControllerTests.m b/UnitTests/MPBackendControllerTests.m index 3f8d0a9b..ab73dc64 100644 --- a/UnitTests/MPBackendControllerTests.m +++ b/UnitTests/MPBackendControllerTests.m @@ -81,7 +81,6 @@ - (void)parseResponseHeader:(NSDictionary *)responseDictionary session:(MPSessio - (NSNumber *)previousSessionSuccessfullyClosed; - (void)setPreviousSessionSuccessfullyClosed:(NSNumber *)previousSessionSuccessfullyClosed; - (void)processOpenSessionsEndingCurrent:(BOOL)endCurrentSession completionHandler:(dispatch_block_t)completionHandler; -- (void)processPendingArchivedMessages; - (void)resetUserIdentitiesFirstTimeUseFlag; - (void)saveMessage:(MPMessage *)message updateSession:(BOOL)updateSession; - (void)uploadMessagesFromSession:(MPSession *)session completionHandler:(void(^)(MPSession *uploadedSession))completionHandler; diff --git a/UnitTests/MPBaseTestCase.m b/UnitTests/MPBaseTestCase.m index e94132c3..e5283f87 100644 --- a/UnitTests/MPBaseTestCase.m +++ b/UnitTests/MPBaseTestCase.m @@ -6,7 +6,6 @@ #import "MPStateMachine.h" #import "MPKitContainer.h" #import "MPAppNotificationHandler.h" -#import "MPArchivist.h" #import "MPConnector.h" #import "MPNetworkCommunication.h" #import "MPConnectorProtocol.h" @@ -70,18 +69,15 @@ - (id)attemptSecureEncodingwithClass:(Class)class Object:(id)object { [fileManager removeItemAtPath:testFile error:nil]; } - NSError *error = nil; - BOOL success = [MPArchivist archiveDataWithRootObject:object toFile:testFile error:&error]; + BOOL success = [NSKeyedArchiver archiveRootObject:object toFile:testFile]; XCTAssertTrue(success); - XCTAssertNil(error); //Retrieve Object XCTAssert([fileManager fileExistsAtPath:testFile]); - id returnedObject = nil; - - returnedObject = [MPArchivist unarchiveObjectOfClass:class withFile:testFile error:nil]; - + id returnedObject = [NSKeyedUnarchiver unarchiveObjectWithFile:testFile]; + XCTAssertNotNil(returnedObject); + //Remove Object if ([fileManager fileExistsAtPath:testFile]) { [fileManager removeItemAtPath:testFile error:nil]; diff --git a/mParticle-Apple-SDK.xcodeproj/project.pbxproj b/mParticle-Apple-SDK.xcodeproj/project.pbxproj index 9441a232..5ced8dde 100644 --- a/mParticle-Apple-SDK.xcodeproj/project.pbxproj +++ b/mParticle-Apple-SDK.xcodeproj/project.pbxproj @@ -156,7 +156,6 @@ 53A79BD529CDFB2000E7489F /* MPResponseEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1029CDFB1F00E7489F /* MPResponseEvents.h */; }; 53A79BD629CDFB2000E7489F /* MPSearchAdsAttribution.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1129CDFB1F00E7489F /* MPSearchAdsAttribution.h */; }; 53A79BD729CDFB2000E7489F /* MPUploadBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */; }; - 53A79BD829CDFB2000E7489F /* MPArchivist.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1329CDFB1F00E7489F /* MPArchivist.m */; }; 53A79BD929CDFB2000E7489F /* MPUserIdentityChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1429CDFB1F00E7489F /* MPUserIdentityChange.m */; }; 53A79BDA29CDFB2000E7489F /* MPDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1529CDFB1F00E7489F /* MPDevice.m */; }; 53A79BDB29CDFB2000E7489F /* MParticleWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1629CDFB1F00E7489F /* MParticleWebView.h */; }; @@ -166,7 +165,6 @@ 53A79BE229CDFB2000E7489F /* MPIUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */; }; 53A79BE329CDFB2000E7489F /* MPBracket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */; }; 53A79BE529CDFB2000E7489F /* MPResponseConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2029CDFB1F00E7489F /* MPResponseConfig.m */; }; - 53A79BE629CDFB2000E7489F /* MPArchivist.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2129CDFB1F00E7489F /* MPArchivist.h */; }; 53A79BE729CDFB2000E7489F /* MPSearchAdsAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2229CDFB1F00E7489F /* MPSearchAdsAttribution.m */; }; 53A79BE829CDFB2000E7489F /* MPUploadBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */; }; 53A79BE929CDFB2000E7489F /* MPApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2429CDFB1F00E7489F /* MPApplication.h */; }; @@ -346,7 +344,6 @@ 53A79D2129CE23F700E7489F /* NSDictionary+MPCaseInsensitive.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79C3329CDFB4800E7489F /* NSDictionary+MPCaseInsensitive.h */; settings = {ATTRIBUTES = (Public, ); }; }; 53A79D2229CE23F700E7489F /* MPCommerceEventInstruction.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79C2F29CDFB4800E7489F /* MPCommerceEventInstruction.h */; settings = {ATTRIBUTES = (Public, ); }; }; 53A79D2329CE23F700E7489F /* MPTransactionAttributes+Dictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79C4429CDFB4800E7489F /* MPTransactionAttributes+Dictionary.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 53A79D2429CE23F700E7489F /* MPArchivist.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2129CDFB1F00E7489F /* MPArchivist.h */; }; 53A79D2529CE23F700E7489F /* MPLaunchInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */; }; 53A79D2729CE23F700E7489F /* MPApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2429CDFB1F00E7489F /* MPApplication.h */; }; 53A79D2829CE23F700E7489F /* MPCustomModulePreference.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2F29CDFB1F00E7489F /* MPCustomModulePreference.h */; }; @@ -439,7 +436,6 @@ 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 */; }; - 53A79D8F29CE23F700E7489F /* MPArchivist.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1329CDFB1F00E7489F /* MPArchivist.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 */; }; @@ -613,7 +609,6 @@ 53A79B1029CDFB1F00E7489F /* MPResponseEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPResponseEvents.h; sourceTree = ""; }; 53A79B1129CDFB1F00E7489F /* MPSearchAdsAttribution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSearchAdsAttribution.h; sourceTree = ""; }; 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPUploadBuilder.m; sourceTree = ""; }; - 53A79B1329CDFB1F00E7489F /* MPArchivist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPArchivist.m; sourceTree = ""; }; 53A79B1429CDFB1F00E7489F /* MPUserIdentityChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPUserIdentityChange.m; sourceTree = ""; }; 53A79B1529CDFB1F00E7489F /* MPDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDevice.m; sourceTree = ""; }; 53A79B1629CDFB1F00E7489F /* MParticleWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MParticleWebView.h; sourceTree = ""; }; @@ -623,7 +618,6 @@ 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 = ""; }; 53A79B2029CDFB1F00E7489F /* MPResponseConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPResponseConfig.m; sourceTree = ""; }; - 53A79B2129CDFB1F00E7489F /* MPArchivist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArchivist.h; sourceTree = ""; }; 53A79B2229CDFB1F00E7489F /* MPSearchAdsAttribution.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSearchAdsAttribution.m; 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 = ""; }; @@ -1034,7 +1028,6 @@ 53A79B1029CDFB1F00E7489F /* MPResponseEvents.h */, 53A79B1129CDFB1F00E7489F /* MPSearchAdsAttribution.h */, 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */, - 53A79B1329CDFB1F00E7489F /* MPArchivist.m */, 53A79B1429CDFB1F00E7489F /* MPUserIdentityChange.m */, 53A79B1529CDFB1F00E7489F /* MPDevice.m */, 53A79B1629CDFB1F00E7489F /* MParticleWebView.h */, @@ -1044,7 +1037,6 @@ 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */, 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */, 53A79B2029CDFB1F00E7489F /* MPResponseConfig.m */, - 53A79B2129CDFB1F00E7489F /* MPArchivist.h */, 53A79B2229CDFB1F00E7489F /* MPSearchAdsAttribution.m */, 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */, 53A79B2429CDFB1F00E7489F /* MPApplication.h */, @@ -1345,7 +1337,6 @@ 53A79C5529CDFB4800E7489F /* NSDictionary+MPCaseInsensitive.h in Headers */, 53A79C5129CDFB4800E7489F /* MPCommerceEventInstruction.h in Headers */, 53A79C6629CDFB4800E7489F /* MPTransactionAttributes+Dictionary.h in Headers */, - 53A79BE629CDFB2000E7489F /* MPArchivist.h in Headers */, 53A79BDC29CDFB2000E7489F /* MPLaunchInfo.h in Headers */, 53A79BE929CDFB2000E7489F /* MPApplication.h in Headers */, 53A79BF329CDFB2000E7489F /* MPCustomModulePreference.h in Headers */, @@ -1444,7 +1435,6 @@ 53A79D2129CE23F700E7489F /* NSDictionary+MPCaseInsensitive.h in Headers */, 53A79D2229CE23F700E7489F /* MPCommerceEventInstruction.h in Headers */, 53A79D2329CE23F700E7489F /* MPTransactionAttributes+Dictionary.h in Headers */, - 53A79D2429CE23F700E7489F /* MPArchivist.h in Headers */, 53A79D2529CE23F700E7489F /* MPLaunchInfo.h in Headers */, 53A79D2729CE23F700E7489F /* MPApplication.h in Headers */, 53A79D2829CE23F700E7489F /* MPCustomModulePreference.h in Headers */, @@ -1777,7 +1767,6 @@ 53A79BF629CDFB2000E7489F /* MPCustomModule.m in Sources */, 53A79C1329CDFB2100E7489F /* MPKitActivity.m in Sources */, 53A79BE229CDFB2000E7489F /* MPIUserDefaults.m in Sources */, - 53A79BD829CDFB2000E7489F /* MPArchivist.m in Sources */, 53A79B8429CDFB2000E7489F /* MPDatabaseMigrationController.m in Sources */, 53A79BC029CDFB2000E7489F /* MPConsentKitFilter.m in Sources */, 53A79C0A29CDFB2100E7489F /* MPKitRegister.m in Sources */, @@ -1948,7 +1937,6 @@ 53A79D8A29CE23F700E7489F /* MPCustomModule.m in Sources */, 53A79D8C29CE23F700E7489F /* MPKitActivity.m in Sources */, 53A79D8E29CE23F700E7489F /* MPIUserDefaults.m in Sources */, - 53A79D8F29CE23F700E7489F /* MPArchivist.m in Sources */, D3CEDAC42C9DB0E0001B32DF /* MPDateFormatter.swift in Sources */, 53A79D9029CE23F700E7489F /* MPDatabaseMigrationController.m in Sources */, 53A79D9129CE23F700E7489F /* MPConsentKitFilter.m in Sources */, diff --git a/mParticle-Apple-SDK/MPBackendController.m b/mParticle-Apple-SDK/MPBackendController.m index 01378993..057b7c91 100644 --- a/mParticle-Apple-SDK/MPBackendController.m +++ b/mParticle-Apple-SDK/MPBackendController.m @@ -29,7 +29,6 @@ #import "MPSearchAdsAttribution.h" #endif #import "MPURLRequestBuilder.h" -#import "MPArchivist.h" #import "MPListenerController.h" #import "MParticleWebView.h" #import "MPDevice.h" @@ -440,40 +439,6 @@ - (void)processOpenSessionsEndingCurrent:(BOOL)endCurrentSession completionHandl [self uploadOpenSessions:sessions completionHandler:completionHandler]; } -- (void)processPendingArchivedMessages { - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *crashLogsDirectoryPath = CRASH_LOGS_DIRECTORY_PATH; - NSString *archivedMessagesDirectoryPath = ARCHIVED_MESSAGES_DIRECTORY_PATH; - NSArray *directoryPaths = @[crashLogsDirectoryPath, archivedMessagesDirectoryPath]; - NSArray *fileExtensions = @[@".log", @".arcmsg"]; - - [directoryPaths enumerateObjectsUsingBlock:^(NSString *directoryPath, NSUInteger idx, BOOL *stop) { - if (![fileManager fileExistsAtPath:directoryPath]) { - return; - } - - NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:directoryPath error:nil]; - NSString *predicateFormat = [NSString stringWithFormat:@"self ENDSWITH '%@'", fileExtensions[idx]]; - NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat]; - directoryContents = [directoryContents filteredArrayUsingPredicate:predicate]; - - for (NSString *fileName in directoryContents) { - NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName]; - @try { - MPMessage *message = [MPArchivist unarchiveObjectOfClass:[MPMessage class] withFile:filePath error:nil]; - - if (message) { - [self saveMessage:message updateSession:NO]; - } - } @catch (NSException* ex) { - MPILogError(@"Failed To retrieve crash messages from archive: %@", ex); - } @finally { - [fileManager removeItemAtPath:filePath error:nil]; - } - } - }]; -} - - (void)proxyOriginalAppDelegate { if (originalAppDelegateProxied && !appDelegateProxy) { return; @@ -1582,7 +1547,6 @@ - (void)startWithKey:(NSString *)apiKey secret:(NSString *)secret networkOptions searchAdsCompletion(); #endif - [self processPendingArchivedMessages]; MPILogDebug(@"SDK %@ has started", kMParticleSDKVersion); completionHandler(); diff --git a/mParticle-Apple-SDK/MPIConstants.h b/mParticle-Apple-SDK/MPIConstants.h index 08ff0a33..bfe55f90 100644 --- a/mParticle-Apple-SDK/MPIConstants.h +++ b/mParticle-Apple-SDK/MPIConstants.h @@ -6,8 +6,6 @@ #define MPMilliseconds(timestamp) @(trunc((timestamp) * 1000)) #define MPCurrentEpochInMilliseconds @(trunc([[NSDate date] timeIntervalSince1970] * 1000)) -#define CRASH_LOGS_DIRECTORY_PATH [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"CrashLogs"]; -#define ARCHIVED_MESSAGES_DIRECTORY_PATH [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"ArchivedMessages"]; #define STATE_MACHINE_DIRECTORY_PATH [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"StateMachine"]; #define MPIsNull(object) ((object) == nil || (NSNull *)(object) == [NSNull null]) diff --git a/mParticle-Apple-SDK/Utils/MPArchivist.h b/mParticle-Apple-SDK/Utils/MPArchivist.h deleted file mode 100644 index e9d7f957..00000000 --- a/mParticle-Apple-SDK/Utils/MPArchivist.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface MPArchivist : NSObject - -+ (BOOL)archiveDataWithRootObject:(id)object toFile:(NSString *)path error:(NSError ** _Nullable)error; -+ (id)unarchiveObjectOfClass:(Class)cls withFile:(NSString *)path error:(NSError ** _Nullable)error; - -@end - -NS_ASSUME_NONNULL_END diff --git a/mParticle-Apple-SDK/Utils/MPArchivist.m b/mParticle-Apple-SDK/Utils/MPArchivist.m deleted file mode 100644 index b3823278..00000000 --- a/mParticle-Apple-SDK/Utils/MPArchivist.m +++ /dev/null @@ -1,37 +0,0 @@ -#import "MPArchivist.h" -#import "mParticle.h" -#import "MPILogger.h" - -@implementation MPArchivist - -+ (BOOL)archiveDataWithRootObject:(id)object toFile:(NSString *)path error:(NSError ** _Nullable)error { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - @try { - if (![NSKeyedArchiver archiveRootObject:object toFile:path]) { - MPILogError(@"Object was not persisted."); - return NO; - } - } @catch(NSException *ex) { - MPILogError(@"Failed To archive: %@", ex); - return NO; - } - return YES; -#pragma clang diagnostic pop -} - -+ (id)unarchiveObjectOfClass:(Class)cls withFile:(NSString *)path error:(NSError ** _Nullable)error { - id object = nil; - @try { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - object = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; -#pragma clang diagnostic pop - } @catch(NSException *ex) { - MPILogError(@"Failed To retrieve %@: %@", cls, ex); - } - - return object; -} - -@end diff --git a/mParticle-Apple-SDK/Utils/MPIUserDefaults.m b/mParticle-Apple-SDK/Utils/MPIUserDefaults.m index 8d2cb71b..3d23f4be 100644 --- a/mParticle-Apple-SDK/Utils/MPIUserDefaults.m +++ b/mParticle-Apple-SDK/Utils/MPIUserDefaults.m @@ -4,7 +4,6 @@ #import "MPILogger.h" #import "mParticle.h" #import "MPKitConfiguration.h" -#import "MPArchivist.h" #import "MPStateMachine.h" #import "MPKitContainer.h" #import "MParticleSwift.h"