From e8aa89623052b69d9c86fba7caa41f2b3cb2331b Mon Sep 17 00:00:00 2001 From: Brandon Stalnaker Date: Mon, 9 Mar 2026 10:19:03 -0400 Subject: [PATCH] fix: Remove Outdated previousSessionSuccessfullyClosed Logic --- .../ObjCTests/MPBackendControllerTests.m | 6 +-- mParticle-Apple-SDK/MPBackendController.m | 47 ------------------- mParticle-Apple-SDK/MPIConstants.h | 2 - mParticle-Apple-SDK/MPIConstants.m | 2 - 4 files changed, 2 insertions(+), 55 deletions(-) diff --git a/UnitTests/ObjCTests/MPBackendControllerTests.m b/UnitTests/ObjCTests/MPBackendControllerTests.m index b24b63567..537f17289 100644 --- a/UnitTests/ObjCTests/MPBackendControllerTests.m +++ b/UnitTests/ObjCTests/MPBackendControllerTests.m @@ -77,8 +77,6 @@ - (void)handleApplicationDidBecomeActive:(NSNotification *)notification; - (void)logRemoteNotificationWithNotificationController:(MPNotificationController_PRIVATE *const)notificationController; - (void)parseConfigResponse:(NSDictionary *)configurationDictionary; - (void)parseResponseHeader:(NSDictionary *)responseDictionary session:(MPSession *)session; -- (NSNumber *)previousSessionSuccessfullyClosed; -- (void)setPreviousSessionSuccessfullyClosed:(NSNumber *)previousSessionSuccessfullyClosed; - (void)processOpenSessionsEndingCurrent:(BOOL)endCurrentSession completionHandler:(dispatch_block_t)completionHandler; - (void)resetUserIdentitiesFirstTimeUseFlag; - (void)saveMessage:(MPMessage *)message updateSession:(BOOL)updateSession; @@ -125,10 +123,10 @@ @implementation MPBackendControllerTests - (void)setUp { [super setUp]; - + [MPPersistenceController_PRIVATE setMpid:@1]; [MParticle sharedInstance].persistenceController = [[MPPersistenceController_PRIVATE alloc] init]; - + // Must read messageQueue AFTER [MParticle sharedInstance] triggers singleton // recreation, otherwise we get the old executor's queue. messageQueue = [MParticle messageQueue]; diff --git a/mParticle-Apple-SDK/MPBackendController.m b/mParticle-Apple-SDK/MPBackendController.m index b674e4e72..02e3cef04 100644 --- a/mParticle-Apple-SDK/MPBackendController.m +++ b/mParticle-Apple-SDK/MPBackendController.m @@ -324,50 +324,6 @@ - (void)logUserIdentityChange:(MPUserIdentityChange_PRIVATE *)userIdentityChange [self saveMessage:message updateSession:YES]; } -- (NSNumber *)previousSessionSuccessfullyClosed { - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *stateMachineDirectoryPath = STATE_MACHINE_DIRECTORY_PATH; - NSString *previousSessionStateFile = [stateMachineDirectoryPath stringByAppendingPathComponent:kMPPreviousSessionStateFileName]; - NSNumber *previousSessionSuccessfullyClosed = nil; - if ([fileManager fileExistsAtPath:previousSessionStateFile]) { - NSDictionary *previousSessionStateDictionary = [NSDictionary dictionaryWithContentsOfFile:previousSessionStateFile]; - previousSessionSuccessfullyClosed = previousSessionStateDictionary[kMPASTPreviousSessionSuccessfullyClosedKey]; - } - - if (previousSessionSuccessfullyClosed == nil) { - previousSessionSuccessfullyClosed = @YES; - } - - return previousSessionSuccessfullyClosed; -} - -- (void)setPreviousSessionSuccessfullyClosed:(NSNumber *)previousSessionSuccessfullyClosed { - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *stateMachineDirectoryPath = STATE_MACHINE_DIRECTORY_PATH; - NSString *previousSessionStateFile = [stateMachineDirectoryPath stringByAppendingPathComponent:kMPPreviousSessionStateFileName]; - NSDictionary *previousSessionStateDictionary = @{kMPASTPreviousSessionSuccessfullyClosedKey:previousSessionSuccessfullyClosed}; - - @try { - if (![fileManager fileExistsAtPath:stateMachineDirectoryPath]) { - NSError *dirError = nil; - [fileManager createDirectoryAtPath:stateMachineDirectoryPath withIntermediateDirectories:YES attributes:nil error:&dirError]; - if (dirError) { - MPILogError(@"Failed to create state machine directory: %@", dirError); - return; - } - } else if ([fileManager fileExistsAtPath:previousSessionStateFile]) { - [fileManager removeItemAtPath:previousSessionStateFile error:nil]; - } - - BOOL success = [previousSessionStateDictionary writeToFile:previousSessionStateFile atomically:YES]; - if (!success) { - MPILogError(@"Failed to write previous session state to file"); - } - } @catch (NSException *exception) { - MPILogError(@"Exception writing previous session state: %@", exception); - } -} - - (void)processDidFinishLaunching:(NSNotification *)notification { NSString *astType = kMPASTInitKey; NSMutableDictionary *messageInfo = [[NSMutableDictionary alloc] initWithCapacity:3]; @@ -384,8 +340,6 @@ - (void)processDidFinishLaunching:(NSNotification *)notification { isInstallOrUpgrade = YES; } - messageInfo[kMPASTPreviousSessionSuccessfullyClosedKey] = [self previousSessionSuccessfullyClosed]; - NSDictionary *userInfo = [notification userInfo]; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { @@ -2136,7 +2090,6 @@ - (void)handleApplicationDidEnterBackground:(NSNotification *)notification { self.timeAppWentToBackgroundInCurrentSession = currentTime; self.timeOfLastEventInBackground = currentTime; - [self setPreviousSessionSuccessfullyClosed:@YES]; [self cleanUp]; MPMessageBuilder *messageBuilder = [[MPMessageBuilder alloc] initWithMessageType:MPMessageTypeAppStateTransition diff --git a/mParticle-Apple-SDK/MPIConstants.h b/mParticle-Apple-SDK/MPIConstants.h index 6a3a55167..1059ed669 100644 --- a/mParticle-Apple-SDK/MPIConstants.h +++ b/mParticle-Apple-SDK/MPIConstants.h @@ -186,7 +186,6 @@ extern NSString * _Nonnull const kMPUploadIntervalKey; extern NSString * _Nonnull const kMPPreviousSessionLengthKey; extern NSString * _Nonnull const kMPLifeTimeValueKey; extern NSString * _Nonnull const kMPIncreasedLifeTimeValueKey; -extern NSString * _Nonnull const kMPPreviousSessionStateFileName; extern NSString * _Nonnull const kMPHTTPMethodPost; extern NSString * _Nonnull const kMPHTTPMethodGet; extern NSString * _Nonnull const kMPPreviousSessionIdKey; @@ -365,7 +364,6 @@ extern NSString * _Nonnull const kMPASTBackgroundKey; extern NSString * _Nonnull const kMPASTForegroundKey; extern NSString * _Nonnull const kMPASTIsFirstRunKey; extern NSString * _Nonnull const kMPASTIsUpgradeKey; -extern NSString * _Nonnull const kMPASTPreviousSessionSuccessfullyClosedKey; // Network performance extern NSString * _Nonnull const kMPNetworkPerformanceMeasurementNotification; diff --git a/mParticle-Apple-SDK/MPIConstants.m b/mParticle-Apple-SDK/MPIConstants.m index 567d69295..ecefbcece 100644 --- a/mParticle-Apple-SDK/MPIConstants.m +++ b/mParticle-Apple-SDK/MPIConstants.m @@ -139,7 +139,6 @@ NSString *const kMPPreviousSessionLengthKey = @"psl"; NSString *const kMPLifeTimeValueKey = @"ltv"; NSString *const kMPIncreasedLifeTimeValueKey = @"iltv"; -NSString *const kMPPreviousSessionStateFileName = @"PreviousSessionState.dic"; NSString *const kMPHTTPMethodPost = @"POST"; NSString *const kMPHTTPMethodGet = @"GET"; NSString *const kMPPreviousSessionIdKey = @"pid"; @@ -310,7 +309,6 @@ NSString *const kMPASTForegroundKey = @"app_fore"; NSString *const kMPASTIsFirstRunKey = @"ifr"; NSString *const kMPASTIsUpgradeKey = @"iu"; -NSString *const kMPASTPreviousSessionSuccessfullyClosedKey = @"sc"; // Network performance NSString *const kMPNetworkPerformanceMeasurementNotification = @"MPNetworkPerformanceMeasurement";