From 8f68ec5d62bee962881de6b520be084e4b8f8a81 Mon Sep 17 00:00:00 2001 From: Brandon Stalnaker Date: Thu, 19 Dec 2024 14:33:15 -0500 Subject: [PATCH] refactor: Port MPLaunchInfo to Swift --- UnitTests/MPBackendControllerTests.m | 1 - UnitTests/MPLaunchInfoTests.m | 8 +- UnitTests/MPStateMachineTests.m | 2 +- mParticle-Apple-SDK.xcodeproj/project.pbxproj | 18 +- .../MPAppNotificationHandler.m | 2 +- mParticle-Apple-SDK/MPBackendController.m | 1 - mParticle-Apple-SDK/MPStateMachine.m | 1 - mParticle-Apple-SDK/Utils/MPLaunchInfo.h | 13 -- mParticle-Apple-SDK/Utils/MPLaunchInfo.m | 169 ------------------ mParticle-Apple-SDK/Utils/MPLaunchInfo.swift | 103 +++++++++++ mParticle-Apple-SDK/Utils/MPMessageBuilder.m | 1 - 11 files changed, 112 insertions(+), 207 deletions(-) delete mode 100644 mParticle-Apple-SDK/Utils/MPLaunchInfo.h delete mode 100644 mParticle-Apple-SDK/Utils/MPLaunchInfo.m create mode 100644 mParticle-Apple-SDK/Utils/MPLaunchInfo.swift diff --git a/UnitTests/MPBackendControllerTests.m b/UnitTests/MPBackendControllerTests.m index 2b5be603f..1af2ad774 100644 --- a/UnitTests/MPBackendControllerTests.m +++ b/UnitTests/MPBackendControllerTests.m @@ -19,7 +19,6 @@ #import "MPBaseTestCase.h" #import "MPIUserDefaults.h" #import "MPDevice.h" -#import "MPLaunchInfo.h" #if TARGET_OS_IOS == 1 #import diff --git a/UnitTests/MPLaunchInfoTests.m b/UnitTests/MPLaunchInfoTests.m index b8ff8a3af..7dfc9b544 100644 --- a/UnitTests/MPLaunchInfoTests.m +++ b/UnitTests/MPLaunchInfoTests.m @@ -1,5 +1,5 @@ #import -#import "MPLaunchInfo.h" +#import "MParticleSwift.h" #import "MParticleSwift.h" #import "MPBaseTestCase.h" @@ -91,12 +91,6 @@ - (void)testInvalidValues { MPLaunchInfo *launchInfo = [[MPLaunchInfo alloc] initWithURL:url sourceApplication:sourceApp annotation:annotation]; XCTAssertNil(launchInfo, @"Should have been nil."); - - url = (NSURL *)[NSNull null]; - sourceApp = nil; - - launchInfo = [[MPLaunchInfo alloc] initWithURL:url sourceApplication:sourceApp annotation:annotation]; - XCTAssertNil(launchInfo, @"Should have been nil."); } - (void)testCreation { diff --git a/UnitTests/MPStateMachineTests.m b/UnitTests/MPStateMachineTests.m index 4240ffc70..1909c8767 100644 --- a/UnitTests/MPStateMachineTests.m +++ b/UnitTests/MPStateMachineTests.m @@ -9,7 +9,7 @@ #import "MPBaseTestCase.h" #import "MPStateMachine.h" #import "MPKitContainer.h" -#import "MPLaunchInfo.h" +#import "MParticleSwift.h" #pragma mark - MPStateMachine category @interface MPStateMachine_PRIVATE(Tests) diff --git a/mParticle-Apple-SDK.xcodeproj/project.pbxproj b/mParticle-Apple-SDK.xcodeproj/project.pbxproj index 75043e4ec..c864f0909 100644 --- a/mParticle-Apple-SDK.xcodeproj/project.pbxproj +++ b/mParticle-Apple-SDK.xcodeproj/project.pbxproj @@ -162,14 +162,12 @@ 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 */; }; - 53A79BDC29CDFB2000E7489F /* MPLaunchInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */; }; 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, ); }; }; 53A79BEB29CDFB2000E7489F /* NSNumber+MPFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */; }; - 53A79BEE29CDFB2000E7489F /* MPLaunchInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */; }; 53A79BF029CDFB2000E7489F /* MPDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2B29CDFB1F00E7489F /* MPDevice.h */; }; 53A79BF129CDFB2000E7489F /* MPBracket.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2C29CDFB1F00E7489F /* MPBracket.h */; }; 53A79BF329CDFB2000E7489F /* MPCustomModulePreference.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2F29CDFB1F00E7489F /* MPCustomModulePreference.h */; }; @@ -341,7 +339,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, ); }; }; - 53A79D2529CE23F700E7489F /* MPLaunchInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */; }; 53A79D2729CE23F700E7489F /* MPApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2429CDFB1F00E7489F /* MPApplication.h */; settings = {ATTRIBUTES = (Public, ); }; }; 53A79D2829CE23F700E7489F /* MPCustomModulePreference.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2F29CDFB1F00E7489F /* MPCustomModulePreference.h */; }; 53A79D2929CE23F700E7489F /* MPDataModelProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AC229CDFB1E00E7489F /* MPDataModelProtocol.h */; }; @@ -412,7 +409,6 @@ 53A79D7929CE23F700E7489F /* MPBracket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */; }; 53A79D7A29CE23F700E7489F /* MParticleUserNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AC729CDFB1E00E7489F /* MParticleUserNotification.m */; }; 53A79D7B29CE23F700E7489F /* MPIConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B6429CDFB1F00E7489F /* MPIConstants.m */; }; - 53A79D7C29CE23F700E7489F /* MPLaunchInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */; }; 53A79D7D29CE23F700E7489F /* MPPromotion.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B4129CDFB1F00E7489F /* MPPromotion.m */; }; 53A79D8129CE23F700E7489F /* MPIdentityApiRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79A9829CDFB1E00E7489F /* MPIdentityApiRequest.m */; }; 53A79D8229CE23F700E7489F /* MPCommerceEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B4029CDFB1F00E7489F /* MPCommerceEvent.mm */; }; @@ -473,6 +469,8 @@ 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, ); }; }; + D346D8DB2D14682000FBA8B1 /* MPLaunchInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */; }; + D346D8DC2D14682000FBA8B1 /* MPLaunchInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */; }; D356E0242CFE08ED0020898D /* MPResponseConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = D356E0232CFE08ED0020898D /* MPResponseConfig.swift */; }; D356E0252CFE08ED0020898D /* MPResponseConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = D356E0232CFE08ED0020898D /* MPResponseConfig.swift */; }; D3724C192AE02AF60074CD67 /* mParticle_Apple_SDK_NoLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = D3724C182AE02AF60074CD67 /* mParticle_Apple_SDK_NoLocation.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -599,14 +597,12 @@ 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 = ""; }; - 53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPLaunchInfo.h; 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 = ""; }; 53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSNumber+MPFormatter.swift"; sourceTree = ""; }; - 53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPLaunchInfo.m; sourceTree = ""; }; 53A79B2B29CDFB1F00E7489F /* MPDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDevice.h; sourceTree = ""; }; 53A79B2C29CDFB1F00E7489F /* MPBracket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPBracket.h; sourceTree = ""; }; 53A79B2F29CDFB1F00E7489F /* MPCustomModulePreference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCustomModulePreference.h; sourceTree = ""; }; @@ -767,6 +763,7 @@ 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 = ""; }; + D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPLaunchInfo.swift; sourceTree = ""; }; D356E0232CFE08ED0020898D /* MPResponseConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPResponseConfig.swift; sourceTree = ""; }; D3724C182AE02AF60074CD67 /* mParticle_Apple_SDK_NoLocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Apple_SDK_NoLocation.h; sourceTree = ""; }; D3961CD52CB468DC003B3194 /* NSArray+MPCaseInsensitive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSArray+MPCaseInsensitive.swift"; sourceTree = ""; }; @@ -1009,13 +1006,12 @@ D3961CDD2CC0B7E4003B3194 /* NSString+MPPercentEscape.swift */, 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */, 53A79B1529CDFB1F00E7489F /* MPDevice.m */, - 53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */, + D346D8DA2D14682000FBA8B1 /* MPLaunchInfo.swift */, 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */, 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */, 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */, 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */, 53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */, - 53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */, 53A79B2B29CDFB1F00E7489F /* MPDevice.h */, 53A79B2C29CDFB1F00E7489F /* MPBracket.h */, 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */, @@ -1313,7 +1309,6 @@ 53A79C5529CDFB4800E7489F /* NSDictionary+MPCaseInsensitive.h in Headers */, 53A79C5129CDFB4800E7489F /* MPCommerceEventInstruction.h in Headers */, 53A79C6629CDFB4800E7489F /* MPTransactionAttributes+Dictionary.h in Headers */, - 53A79BDC29CDFB2000E7489F /* MPLaunchInfo.h in Headers */, 53A79BE929CDFB2000E7489F /* MPApplication.h in Headers */, D30CD0CB2CFF5FB100F5148A /* MPStateMachine.h in Headers */, 53A79BF329CDFB2000E7489F /* MPCustomModulePreference.h in Headers */, @@ -1405,7 +1400,6 @@ 53A79D2129CE23F700E7489F /* NSDictionary+MPCaseInsensitive.h in Headers */, 53A79D2229CE23F700E7489F /* MPCommerceEventInstruction.h in Headers */, 53A79D2329CE23F700E7489F /* MPTransactionAttributes+Dictionary.h in Headers */, - 53A79D2529CE23F700E7489F /* MPLaunchInfo.h in Headers */, 53A79D2729CE23F700E7489F /* MPApplication.h in Headers */, 53A79D2829CE23F700E7489F /* MPCustomModulePreference.h in Headers */, 53A79D2929CE23F700E7489F /* MPDataModelProtocol.h in Headers */, @@ -1718,7 +1712,6 @@ 53A79B9129CDFB2000E7489F /* MParticleUserNotification.m in Sources */, 53A79C2129CDFB2100E7489F /* MPIConstants.m in Sources */, 530D24832CFF72D9000FE7E3 /* MPConstants.swift in Sources */, - 53A79BEE29CDFB2000E7489F /* MPLaunchInfo.m in Sources */, 53A79C0229CDFB2100E7489F /* MPPromotion.m in Sources */, D356E0242CFE08ED0020898D /* MPResponseConfig.swift in Sources */, 53A79B6629CDFB2000E7489F /* MPIdentityApiRequest.m in Sources */, @@ -1747,6 +1740,7 @@ 53B33E8A2A4606CD00CC8A19 /* MPSideloadedKit.swift in Sources */, 53A79B9629CDFB2000E7489F /* MPSession.m in Sources */, 53A79B9729CDFB2000E7489F /* MPIntegrationAttributes.m in Sources */, + D346D8DB2D14682000FBA8B1 /* MPLaunchInfo.swift in Sources */, D3CEDAC82CA2F214001B32DF /* MPLogger.swift in Sources */, 53A79B6A29CDFB2000E7489F /* MPAliasRequest.m in Sources */, 53A79B6829CDFB2000E7489F /* MParticleUser.m in Sources */, @@ -1886,7 +1880,6 @@ 53A79D7A29CE23F700E7489F /* MParticleUserNotification.m in Sources */, 531BCF372B28A23400F5C573 /* MPIdentityCaching.m in Sources */, 53A79D7B29CE23F700E7489F /* MPIConstants.m in Sources */, - 53A79D7C29CE23F700E7489F /* MPLaunchInfo.m in Sources */, 530D24822CFF72D9000FE7E3 /* MPConstants.swift in Sources */, 53A79D7D29CE23F700E7489F /* MPPromotion.m in Sources */, 534CD25C29CE2877008452B3 /* NSNumber+MPFormatter.swift in Sources */, @@ -1917,6 +1910,7 @@ 53A79D9929CE23F700E7489F /* MPDataPlanFilter.m in Sources */, 53B33E8B2A4606CD00CC8A19 /* MPSideloadedKit.swift in Sources */, 53A79D9A29CE23F700E7489F /* MPSession.m in Sources */, + D346D8DC2D14682000FBA8B1 /* MPLaunchInfo.swift in Sources */, 53A79D9B29CE23F700E7489F /* MPIntegrationAttributes.m in Sources */, D3CEDAC92CA2F214001B32DF /* MPLogger.swift in Sources */, 53A79D9C29CE23F700E7489F /* MPAliasRequest.m in Sources */, diff --git a/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m b/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m index 9e4b299a6..553024dae 100644 --- a/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m +++ b/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m @@ -1,5 +1,4 @@ #import "MPAppNotificationHandler.h" -#import "MPLaunchInfo.h" #import "MPForwardRecord.h" #import "MPPersistenceController.h" #import "MPILogger.h" @@ -9,6 +8,7 @@ #import "MPForwardQueueParameters.h" #import "MPKitAPI.h" #import "MPApplication.h" +#import "MParticleSwift.h" #import "mParticle.h" #if TARGET_OS_IOS == 1 diff --git a/mParticle-Apple-SDK/MPBackendController.m b/mParticle-Apple-SDK/MPBackendController.m index f3910b443..5f0ac4ff2 100644 --- a/mParticle-Apple-SDK/MPBackendController.m +++ b/mParticle-Apple-SDK/MPBackendController.m @@ -26,7 +26,6 @@ #import "MPDevice.h" #import "MPIdentityCaching.h" #import "MParticleSwift.h" -#import "MPLaunchInfo.h" #import "MPNetworkCommunication.h" #if TARGET_OS_IOS == 1 #import "MPNotificationController.h" diff --git a/mParticle-Apple-SDK/MPStateMachine.m b/mParticle-Apple-SDK/MPStateMachine.m index ee20dceb9..45eba3b62 100644 --- a/mParticle-Apple-SDK/MPStateMachine.m +++ b/mParticle-Apple-SDK/MPStateMachine.m @@ -14,7 +14,6 @@ #import "MPForwardQueueParameters.h" #import "MPDataPlanFilter.h" #import "MParticleSwift.h" -#import "MPLaunchInfo.h" #import "MParticleReachability.h" #import "MPIConstants.h" diff --git a/mParticle-Apple-SDK/Utils/MPLaunchInfo.h b/mParticle-Apple-SDK/Utils/MPLaunchInfo.h deleted file mode 100644 index c4ac6e7bc..000000000 --- a/mParticle-Apple-SDK/Utils/MPLaunchInfo.h +++ /dev/null @@ -1,13 +0,0 @@ -#import - -@interface MPLaunchInfo : NSObject - -@property (nonatomic, strong, readonly, nonnull) NSURL *url; -@property (nonatomic, strong, readonly, nullable) NSString *sourceApplication; -@property (nonatomic, strong, readonly, nullable) NSString *annotation; -@property (nonatomic, strong, readonly, nullable) NSDictionary *options; - -- (nonnull instancetype)initWithURL:(nonnull NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(nullable id)annotation; -- (nonnull instancetype)initWithURL:(nonnull NSURL *)url options:(nullable NSDictionary *)options; - -@end diff --git a/mParticle-Apple-SDK/Utils/MPLaunchInfo.m b/mParticle-Apple-SDK/Utils/MPLaunchInfo.m deleted file mode 100644 index 0e3045a28..000000000 --- a/mParticle-Apple-SDK/Utils/MPLaunchInfo.m +++ /dev/null @@ -1,169 +0,0 @@ -#import "MPLaunchInfo.h" -#import "MPIConstants.h" -#import -#import "MParticleSwift.h" -#import "MPILogger.h" -#import "mParticle.h" - -@interface MPLaunchInfo() { - NSString *sourceApp; -} - -@property (nonatomic, strong, readonly) NSString *annotationKey; -@property (nonatomic, strong, readonly) NSString *sourceAppKey; - -@end - - -@implementation MPLaunchInfo - -@synthesize sourceAppKey = _sourceAppKey; -@synthesize annotationKey = _annotationKey; - -- (instancetype)initWithURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { - self = [super init]; - if (!self || MPIsNull(url)) { - return nil; - } - - sourceApp = sourceApplication; - self.url = url; - self.annotation = annotation; - - NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithCapacity:2]; - - if (_sourceApplication) { - options[self.sourceAppKey] = _sourceApplication; - } - - if (_annotation) { - options[self.annotationKey] = _annotation; - } - - if (options.count > 0) { - _options = [options copy]; - } - - return self; -} - -- (nonnull instancetype)initWithURL:(nonnull NSURL *)url options:(nullable NSDictionary *)options { - self = [super init]; - if (!self || MPIsNull(url)) { - return nil; - } - - _options = options; - sourceApp = options[self.sourceAppKey]; - self.annotation = options[self.annotationKey]; - self.url = url; - - return self; -} - -#pragma mark Private accessors -- (NSString *)annotationKey { - if (_annotationKey) { - return _annotationKey; - } - - _annotationKey = UIApplicationOpenURLOptionsAnnotationKey; - - return _annotationKey; -} - -- (NSString *)sourceAppKey { - if (_sourceAppKey) { - return _sourceAppKey; - } - - _sourceAppKey = UIApplicationOpenURLOptionsSourceApplicationKey; - - return _sourceAppKey; -} - -#pragma mark Public accessors -- (void)setAnnotation:(id)annotation { - Class NSDateClass = [NSDate class]; - Class NSDataClass = [NSData class]; - Class NSDictionaryClass = [NSDictionary class]; - Class NSArrayClass = [NSArray class]; - Class NSSetClass = [NSSet class]; - - id (^valueFromObject)(id) = ^(id obj) { - id value = nil; - - if ([obj isKindOfClass:NSDateClass]) { - value = [MPDateFormatter stringFromDateRFC3339:obj]; - } else if ([obj isKindOfClass:NSDataClass] || [obj isKindOfClass:NSDictionaryClass] || [obj isKindOfClass:NSArrayClass] || [obj isKindOfClass:NSSetClass]) { - value = nil; - } else { - value = obj; - } - - return value; - }; - - NSString * (^serializeDataObject)(id) = ^(id annotationObject) { - NSData *annotationData = nil; - NSError *error = nil; - - @try { - annotationData = [NSJSONSerialization dataWithJSONObject:annotationObject options:0 error:&error]; - } @catch (NSException *exception) { - MPILogError(@"Error serializing annotation from app launch: %@", annotationObject); - return (NSString *)nil; - } - - NSString *serializedAnnotation = !error ? [[NSString alloc] initWithData:annotationData encoding:NSUTF8StringEncoding] : nil; - return serializedAnnotation; - }; - - if ([annotation isKindOfClass:[NSDictionary class]]) { - __block NSMutableDictionary *annotationDictionary = [[NSMutableDictionary alloc] initWithCapacity:((NSDictionary *)annotation).count]; - - [((NSDictionary *)annotation) enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { - id value = valueFromObject(obj); - - if (value) { - annotationDictionary[key] = value; - } - }]; - - _annotation = serializeDataObject(annotationDictionary); - } else if ([annotation isKindOfClass:[NSArray class]]) { - __block NSMutableArray *annotationArray = [[NSMutableArray alloc] initWithCapacity:((NSArray *)annotation).count]; - - [((NSArray *)annotation) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - id value = valueFromObject(obj); - - if (value) { - [annotationArray addObject:value]; - } - }]; - - _annotation = serializeDataObject(annotationArray); - } else if ([annotation isKindOfClass:[NSString class]]) { - _annotation = annotation; - } else if ([annotation isKindOfClass:[NSNumber class]]) { - _annotation = [annotation stringValue]; - } else if ([annotation isKindOfClass:NSDateClass]) { - _annotation = valueFromObject(annotation); - } else { - _annotation = nil; - } -} - -- (void)setUrl:(NSURL *)url { - _url = url; - - if (sourceApp) { - NSString *urlString = [url absoluteString]; - NSRange appLinksRange = [urlString rangeOfString:@"al_applink_data"]; - _sourceApplication = appLinksRange.location == NSNotFound ? sourceApp : [[NSString alloc] initWithFormat:@"AppLink(%@)", sourceApp]; - } else { - _sourceApplication = nil; - } -} - -@end diff --git a/mParticle-Apple-SDK/Utils/MPLaunchInfo.swift b/mParticle-Apple-SDK/Utils/MPLaunchInfo.swift new file mode 100644 index 000000000..a2ba2b8e5 --- /dev/null +++ b/mParticle-Apple-SDK/Utils/MPLaunchInfo.swift @@ -0,0 +1,103 @@ +// +// MPLaunchInfo.swift +// mParticle-Apple-SDK +// +// Created by Brandon Stalnaker on 12/18/24. +// + +import Foundation +@objc public class MPLaunchInfo : NSObject { + @objc private var sourceApp: String? + @objc public private(set) var url: URL + @objc public private(set) var sourceApplication: String? + @objc public private(set) var annotation: String? + @objc public private(set) var options: [String : Any]? + + @objc(initWithURL:sourceApplication:annotation:) public init?(url: URL?, sourceApplication: String?, annotation: Any?) { + guard let url else { return nil } + + self.sourceApp = sourceApplication + self.url = url + super.init() + + if let sourceApp = self.sourceApp { + let urlString = url.absoluteString + let appLinksRange = urlString.range(of: "al_applink_data") + self.sourceApplication = appLinksRange == nil ? sourceApp : "AppLink(\(sourceApp))" + } else { + self.sourceApplication = nil + } + + self.annotation = convertAnnotationToString(rawAnnotation: annotation) + + self.options = [:] + if self.sourceApplication != nil { + self.options?[UIApplication.OpenURLOptionsKey.sourceApplication.rawValue] = self.sourceApplication + } + if self.annotation != nil { + self.options?[UIApplication.OpenURLOptionsKey.annotation.rawValue] = self.annotation + } + } + + @objc(initWithURL:options:) public init?(url: URL?, options: [String : Any]? = nil) { + guard let url else { return nil } + + self.sourceApp = options?[UIApplication.OpenURLOptionsKey.sourceApplication.rawValue] as? String + self.annotation = options?[UIApplication.OpenURLOptionsKey.annotation.rawValue] as? String + self.url = url + super.init() + + if let sourceApp = self.sourceApp { + let urlString = url.absoluteString + let appLinksRange = urlString.range(of: "al_applink_data") + self.sourceApplication = appLinksRange == nil ? sourceApp : "AppLink(\(sourceApp))" + } else { + self.sourceApplication = nil + } + } + + private func convertAnnotationToString(rawAnnotation: Any?) -> String? { + guard let rawAnnotation else { return nil } + + if let annotationString = rawAnnotation as? String { + return annotationString + } else if let annotationDictionary = rawAnnotation as? [String : Any] { + var finalDict: [String : String] = [:] + for (key, value) in annotationDictionary { + if let valueString = self.convertAnnotationToString(rawAnnotation: value) { + finalDict[key] = valueString + } + } + if finalDict.isEmpty { return nil } else { + return serializeObject(finalDict) + } + } else if let annotationArray = rawAnnotation as? [Any] { + var finalArray: [String] = [] + for value in annotationArray { + if let valueString = self.convertAnnotationToString(rawAnnotation: value) { + finalArray.append(valueString) + } + } + if finalArray.isEmpty { return nil } else { + return serializeObject(finalArray) + } + } else if let annotationString = rawAnnotation as? String { + return annotationString + } else if let annotationNumber = rawAnnotation as? NSNumber { + return annotationNumber.stringValue + } else if let annotationDate = rawAnnotation as? Date { + return MPDateFormatter.string(fromDateRFC3339: annotationDate) + } else { + return nil + } + } + + private func serializeObject(_ object: Any) -> String? { + if let dictData = try? JSONSerialization.data(withJSONObject: object, options: []) { + return String(data: dictData, encoding: .utf8) + } else { + MPLog.error("Error serializing annotation from app launch: \(object)") + return nil + } + } +} diff --git a/mParticle-Apple-SDK/Utils/MPMessageBuilder.m b/mParticle-Apple-SDK/Utils/MPMessageBuilder.m index eec2c2625..6465e6634 100644 --- a/mParticle-Apple-SDK/Utils/MPMessageBuilder.m +++ b/mParticle-Apple-SDK/Utils/MPMessageBuilder.m @@ -12,7 +12,6 @@ #import "MPApplication.h" #import "mParticle.h" #import "MParticleSwift.h" -#import "MPLaunchInfo.h" NSString *const launchInfoStringFormat = @"%@%@%@=%@"; NSString *const kMPHorizontalAccuracyKey = @"acc";