diff --git a/Cartfile b/Cartfile index e561982..bb6e4ae 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -#github "Example/Example" ~> 1.2.3 -github "mparticle/mparticle-apple-sdk" ~> 7.7.0 +binary "https://raw.githubusercontent.com/UserLeap/userleap-ios-sdk-releases/main/UserLeapKit.json" +github "mparticle/mparticle-apple-sdk" ~> 8.2.0 diff --git a/mParticle-Example.podspec b/mParticle-Example.podspec deleted file mode 100644 index 9fe1d29..0000000 --- a/mParticle-Example.podspec +++ /dev/null @@ -1,20 +0,0 @@ -Pod::Spec.new do |s| - s.name = "mParticle-Example" - s.version = "7.7.3" - s.summary = "Example integration for mParticle" - - s.description = <<-DESC - This is the Example integration for mParticle. - DESC - - s.homepage = "https://www.mparticle.com" - s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } - s.author = { "mParticle" => "support@mparticle.com" } - s.source = { :git => "https://github.com/mparticle-integrations/mparticle-apple-integration-example.git", :tag => s.version.to_s } - s.social_media_url = "https://twitter.com/mparticle" - - s.ios.deployment_target = "9.0" - s.ios.source_files = 'mParticle-Example/*.{h,m}' - s.ios.dependency 'mParticle-Apple-SDK', '~> 7.7.0' - #s.ios.dependency 'Example', '~> 1.2' -end diff --git a/mParticle-Example/MPKitExample.m b/mParticle-Example/MPKitExample.m deleted file mode 100644 index 66d5d31..0000000 --- a/mParticle-Example/MPKitExample.m +++ /dev/null @@ -1,322 +0,0 @@ -#import "MPKitExample.h" - -/* Import your header file here -*/ -//#if defined(__has_include) && __has_include() -//#import -//#else -//#import "Example.h" -//#endif - -@implementation MPKitExample - -/* - mParticle will supply a unique kit code for you. Please contact our team -*/ -+ (NSNumber *)kitCode { - return @123; -} - -+ (void)load { - MPKitRegister *kitRegister = [[MPKitRegister alloc] initWithName:@"Example" className:@"MPKitExample"]; - [MParticle registerExtension:kitRegister]; -} - -- (MPKitExecStatus *)execStatus:(MPKitReturnCode)returnCode { - return [[MPKitExecStatus alloc] initWithSDKCode:self.class.kitCode returnCode:returnCode]; -} - -#pragma mark - MPKitInstanceProtocol methods - -#pragma mark Kit instance and lifecycle -- (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configuration { - NSString *apiKey = configuration[@""]; - if (!apiKey) { - return [self execStatus:MPKitReturnCodeRequirementsNotMet]; - } - - _configuration = configuration; - - [self start]; - - return [self execStatus:MPKitReturnCodeSuccess]; -} - -- (void)start { - static dispatch_once_t kitPredicate; - - dispatch_once(&kitPredicate, ^{ - /* - Start your SDK here. The configuration dictionary can be retrieved from self->_configuration - */ - - self->_started = YES; - - dispatch_async(dispatch_get_main_queue(), ^{ - NSDictionary *userInfo = @{mParticleKitInstanceKey:[[self class] kitCode]}; - - [[NSNotificationCenter defaultCenter] postNotificationName:mParticleKitDidBecomeActiveNotification - object:nil - userInfo:userInfo]; - }); - }); -} - -- (id const)providerKitInstance { - if (![self started]) { - return nil; - } - - /* - If your company SDK instance is available and is applicable (Please return nil if your SDK is based on class methods) - */ - BOOL kitInstanceAvailable = NO; - if (kitInstanceAvailable) { - /* Return an instance of your company's SDK (if applicable) */ - return nil; - } else { - return nil; - } -} - - -#pragma mark Application -/* - Implement this method if your SDK handles a user interacting with a remote notification action -*/ -// - (MPKitExecStatus *)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -/* - Implement this method if your SDK receives and handles remote notifications -*/ -// - (MPKitExecStatus *)receivedUserNotification:(NSDictionary *)userInfo { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -/* - Implement this method if your SDK registers the device token for remote notifications -*/ -// - (MPKitExecStatus *)setDeviceToken:(NSData *)deviceToken { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -/* - Implement this method if your SDK handles continueUserActivity method from the App Delegate -*/ -// - (nonnull MPKitExecStatus *)continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(void(^ _Nonnull)(NSArray * _Nullable restorableObjects))restorationHandler { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -/* - Implement this method if your SDK handles the iOS 9 and above App Delegate method to open URL with options -*/ -// - (nonnull MPKitExecStatus *)openURL:(nonnull NSURL *)url options:(nullable NSDictionary *)options { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -/* - Implement this method if your SDK handles the iOS 8 and below App Delegate method open URL -*/ -// - (nonnull MPKitExecStatus *)openURL:(nonnull NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(nullable id)annotation { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -#pragma mark User attributes -/* - Implement this method if your SDK allows for incrementing numeric user attributes. -*/ -//- (MPKitExecStatus *)onIncrementUserAttribute:(FilteredMParticleUser *)user { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -/* - Implement this method if your SDK resets user attributes. -*/ -//- (MPKitExecStatus *)onRemoveUserAttribute:(FilteredMParticleUser *)user { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -/* - Implement this method if your SDK sets user attributes. -*/ -//- (MPKitExecStatus *)onSetUserAttribute:(FilteredMParticleUser *)user { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -/* - Implement this method if your SDK supports setting value-less attributes -*/ -//- (MPKitExecStatus *)onSetUserTag:(FilteredMParticleUser *)user { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -#pragma mark Identity -/* - Implement this method if your SDK should be notified any time the mParticle ID (MPID) changes. This will occur on initial install of the app, and potentially after a login or logout. -*/ -//- (MPKitExecStatus *)onIdentifyComplete:(FilteredMParticleUser *)user request:(FilteredMPIdentityApiRequest *)request { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -/* - Implement this method if your SDK should be notified when the user logs in -*/ -//- (MPKitExecStatus *)onLoginComplete:(FilteredMParticleUser *)user request:(FilteredMPIdentityApiRequest *)request { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -/* - Implement this method if your SDK should be notified when the user logs out -*/ -//- (MPKitExecStatus *)onLogoutComplete:(FilteredMParticleUser *)user request:(FilteredMPIdentityApiRequest *)request { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -/* - Implement this method if your SDK should be notified when user identities change -*/ -//- (MPKitExecStatus *)onModifyComplete:(FilteredMParticleUser *)user request:(FilteredMPIdentityApiRequest *)request { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -//} - -#pragma mark e-Commerce -/* - Implement this method if your SDK supports commerce events. - If your SDK does support commerce event, but does not support all commerce event actions available in the mParticle SDK, - expand the received commerce event into regular events and log them accordingly (see sample code below) - Please see MPCommerceEvent.h > MPCommerceEventAction for complete list -*/ -// - (MPKitExecStatus *)logCommerceEvent:(MPCommerceEvent *)commerceEvent { -// MPKitExecStatus *execStatus = [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess forwardCount:0]; -// -// // In this example, this SDK only supports the 'Purchase' commerce event action -// if (commerceEvent.action == MPCommerceEventActionPurchase) { -// /* Your code goes here. */ -// -// [execStatus incrementForwardCount]; -// } -// } else { // Other commerce events are expanded and logged as regular events -// NSArray *expandedInstructions = [commerceEvent expandedInstructions]; -// -// for (MPCommerceEventInstruction *commerceEventInstruction in expandedInstructions) { -// [self logEvent:commerceEventInstruction.event]; -// [execStatus incrementForwardCount]; -// } -// } -// -// return execStatus; -// } - -#pragma mark Events -/* - Implement this method if your SDK logs user events. - Please see MPEvent.h -*/ -// - (MPKitExecStatus *)logEvent:(MPEvent *)event { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -/* - Implement this method if your SDK logs screen events - Please see MPEvent.h -*/ -// - (MPKitExecStatus *)logScreen:(MPEvent *)event { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -#pragma mark Assorted -/* - Implement this method if your SDK implements an opt out mechanism for users. -*/ -// - (MPKitExecStatus *)setOptOut:(BOOL)optOut { -// /* Your code goes here. -// If the execution is not successful, please use a code other than MPKitReturnCodeSuccess for the execution status. -// Please see MPKitExecStatus.h for all exec status codes -// */ -// -// return [self execStatus:MPKitReturnCodeSuccess]; -// } - -@end diff --git a/mParticle-UserLeap.podspec b/mParticle-UserLeap.podspec new file mode 100644 index 0000000..e136849 --- /dev/null +++ b/mParticle-UserLeap.podspec @@ -0,0 +1,26 @@ +Pod::Spec.new do |s| + s.name = "mParticle-UserLeap" + s.version = "1.0.0" + s.summary = "UserLeap integration for mParticle" + + s.description = <<-DESC + Please find updated documentation at https://docs.userleap.com/integrations/mparticle + DESC + + s.homepage = "https://www.mparticle.com" + s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } + s.author = { "UserLeap" => "support@userleap.com" } + s.source = { :git => "https://github.com/UserLeap/userleap-mparticle-ios-kit.git", :tag => s.version.to_s } + s.social_media_url = "https://twitter.com/userleap" + + s.ios.deployment_target = "10.3" + s.ios.source_files = 'mParticle-UserLeap/*.{h,m}' + s.ios.dependency 'mParticle-Apple-SDK', '~> 8.2' + s.ios.dependency 'UserLeapKit', '4.1.0' + s.pod_target_xcconfig = { + 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' + } + s.user_target_xcconfig = { + 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' + } +end diff --git a/mParticle-Example.xcodeproj/project.pbxproj b/mParticle-UserLeap.xcodeproj/project.pbxproj similarity index 70% rename from mParticle-Example.xcodeproj/project.pbxproj rename to mParticle-UserLeap.xcodeproj/project.pbxproj index 39bf8e9..ec4a438 100644 --- a/mParticle-Example.xcodeproj/project.pbxproj +++ b/mParticle-UserLeap.xcodeproj/project.pbxproj @@ -7,12 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - DBB01A601DC1478A00A7B188 /* mParticle_Example.h in Headers */ = {isa = PBXBuildFile; fileRef = DBB01A5E1DC1478A00A7B188 /* mParticle_Example.h */; settings = {ATTRIBUTES = (Public, ); }; }; - DBB01A681DC1480700A7B188 /* MPKitExample.h in Headers */ = {isa = PBXBuildFile; fileRef = DBB01A661DC1480700A7B188 /* MPKitExample.h */; }; - DBB01A691DC1480700A7B188 /* MPKitExample.m in Sources */ = {isa = PBXBuildFile; fileRef = DBB01A671DC1480700A7B188 /* MPKitExample.m */; }; + DAD96C8624DB31DB0021695F /* UserLeapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAD96C8524DB31DB0021695F /* UserLeapKit.framework */; }; + DAD96C8724DB31DB0021695F /* UserLeapKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DAD96C8524DB31DB0021695F /* UserLeapKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + DADFEBB024DB2F0600F96A85 /* MPKitUserLeap.h in Headers */ = {isa = PBXBuildFile; fileRef = DADFEBAD24DB2F0600F96A85 /* MPKitUserLeap.h */; }; + DADFEBB124DB2F0600F96A85 /* mParticle_UserLeap.h in Headers */ = {isa = PBXBuildFile; fileRef = DADFEBAE24DB2F0600F96A85 /* mParticle_UserLeap.h */; }; + DADFEBB224DB2F0600F96A85 /* MPKitUserLeap.m in Sources */ = {isa = PBXBuildFile; fileRef = DADFEBAF24DB2F0600F96A85 /* MPKitUserLeap.m */; }; + DADFEBB824DB30C400F96A85 /* mParticle_UserLeapTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DADFEBB724DB30C400F96A85 /* mParticle_UserLeapTests.m */; }; DBB01A6B1DC1491D00A7B188 /* mParticle_Apple_SDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DBB01A6A1DC1491D00A7B188 /* mParticle_Apple_SDK.framework */; }; - FF0BB63E217A84E800B0556C /* mParticle_ExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FF0BB63D217A84E800B0556C /* mParticle_ExampleTests.m */; }; - FF0BB640217A84E800B0556C /* mParticle_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DBB01A5B1DC1478A00A7B188 /* mParticle_Example.framework */; }; + FF0BB640217A84E800B0556C /* mParticle_UserLeap.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DBB01A5B1DC1478A00A7B188 /* mParticle_UserLeap.framework */; }; FF13226221878D9C002AA653 /* mParticle_Apple_SDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DBB01A6A1DC1491D00A7B188 /* mParticle_Apple_SDK.framework */; }; /* End PBXBuildFile section */ @@ -26,16 +28,31 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + DAD96C8824DB31DB0021695F /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + DAD96C8724DB31DB0021695F /* UserLeapKit.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ - DBB01A5B1DC1478A00A7B188 /* mParticle_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - DBB01A5E1DC1478A00A7B188 /* mParticle_Example.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Example.h; sourceTree = ""; }; + DAD96C8524DB31DB0021695F /* UserLeapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserLeapKit.framework; path = Carthage/Build/iOS/UserLeapKit.framework; sourceTree = ""; }; + DADFEBAD24DB2F0600F96A85 /* MPKitUserLeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPKitUserLeap.h; sourceTree = ""; }; + DADFEBAE24DB2F0600F96A85 /* mParticle_UserLeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mParticle_UserLeap.h; sourceTree = ""; }; + DADFEBAF24DB2F0600F96A85 /* MPKitUserLeap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPKitUserLeap.m; sourceTree = ""; }; + DADFEBB424DB2F3800F96A85 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DADFEBB724DB30C400F96A85 /* mParticle_UserLeapTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = mParticle_UserLeapTests.m; sourceTree = ""; }; + DBB01A5B1DC1478A00A7B188 /* mParticle_UserLeap.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_UserLeap.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DBB01A5F1DC1478A00A7B188 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - DBB01A661DC1480700A7B188 /* MPKitExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPKitExample.h; sourceTree = ""; }; - DBB01A671DC1480700A7B188 /* MPKitExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPKitExample.m; sourceTree = ""; }; DBB01A6A1DC1491D00A7B188 /* mParticle_Apple_SDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = mParticle_Apple_SDK.framework; path = Carthage/Build/iOS/mParticle_Apple_SDK.framework; sourceTree = ""; }; - FF0BB63B217A84E800B0556C /* mParticle_ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = mParticle_ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - FF0BB63D217A84E800B0556C /* mParticle_ExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = mParticle_ExampleTests.m; sourceTree = ""; }; - FF0BB63F217A84E800B0556C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + FF0BB63B217A84E800B0556C /* mParticle_UserLeapTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = mParticle_UserLeapTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -43,6 +60,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + DAD96C8624DB31DB0021695F /* UserLeapKit.framework in Frameworks */, DBB01A6B1DC1491D00A7B188 /* mParticle_Apple_SDK.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -51,7 +69,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FF0BB640217A84E800B0556C /* mParticle_Example.framework in Frameworks */, + FF0BB640217A84E800B0556C /* mParticle_UserLeap.framework in Frameworks */, FF13226221878D9C002AA653 /* mParticle_Apple_SDK.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -63,8 +81,8 @@ isa = PBXGroup; children = ( DBB01A6A1DC1491D00A7B188 /* mParticle_Apple_SDK.framework */, - DBB01A5D1DC1478A00A7B188 /* mParticle-Example */, - FF0BB63C217A84E800B0556C /* mParticle_ExampleTests */, + DBB01A5D1DC1478A00A7B188 /* mParticle-UserLeap */, + FF0BB63C217A84E800B0556C /* mParticle_UserLeapTests */, DBB01A5C1DC1478A00A7B188 /* Products */, FF13226121878D9C002AA653 /* Frameworks */, ); @@ -73,35 +91,36 @@ DBB01A5C1DC1478A00A7B188 /* Products */ = { isa = PBXGroup; children = ( - DBB01A5B1DC1478A00A7B188 /* mParticle_Example.framework */, - FF0BB63B217A84E800B0556C /* mParticle_ExampleTests.xctest */, + DBB01A5B1DC1478A00A7B188 /* mParticle_UserLeap.framework */, + FF0BB63B217A84E800B0556C /* mParticle_UserLeapTests.xctest */, ); name = Products; sourceTree = ""; }; - DBB01A5D1DC1478A00A7B188 /* mParticle-Example */ = { + DBB01A5D1DC1478A00A7B188 /* mParticle-UserLeap */ = { isa = PBXGroup; children = ( - DBB01A661DC1480700A7B188 /* MPKitExample.h */, - DBB01A671DC1480700A7B188 /* MPKitExample.m */, - DBB01A5E1DC1478A00A7B188 /* mParticle_Example.h */, + DADFEBAE24DB2F0600F96A85 /* mParticle_UserLeap.h */, + DADFEBAD24DB2F0600F96A85 /* MPKitUserLeap.h */, + DADFEBAF24DB2F0600F96A85 /* MPKitUserLeap.m */, DBB01A5F1DC1478A00A7B188 /* Info.plist */, ); - path = "mParticle-Example"; + path = "mParticle-UserLeap"; sourceTree = ""; }; - FF0BB63C217A84E800B0556C /* mParticle_ExampleTests */ = { + FF0BB63C217A84E800B0556C /* mParticle_UserLeapTests */ = { isa = PBXGroup; children = ( - FF0BB63D217A84E800B0556C /* mParticle_ExampleTests.m */, - FF0BB63F217A84E800B0556C /* Info.plist */, + DADFEBB724DB30C400F96A85 /* mParticle_UserLeapTests.m */, + DADFEBB424DB2F3800F96A85 /* Info.plist */, ); - path = mParticle_ExampleTests; + path = mParticle_UserLeapTests; sourceTree = ""; }; FF13226121878D9C002AA653 /* Frameworks */ = { isa = PBXGroup; children = ( + DAD96C8524DB31DB0021695F /* UserLeapKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -113,48 +132,48 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - DBB01A601DC1478A00A7B188 /* mParticle_Example.h in Headers */, - DBB01A681DC1480700A7B188 /* MPKitExample.h in Headers */, + DADFEBB024DB2F0600F96A85 /* MPKitUserLeap.h in Headers */, + DADFEBB124DB2F0600F96A85 /* mParticle_UserLeap.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - DBB01A5A1DC1478A00A7B188 /* mParticle-Example */ = { + DBB01A5A1DC1478A00A7B188 /* mParticle-UserLeap */ = { isa = PBXNativeTarget; - buildConfigurationList = DBB01A631DC1478A00A7B188 /* Build configuration list for PBXNativeTarget "mParticle-Example" */; + buildConfigurationList = DBB01A631DC1478A00A7B188 /* Build configuration list for PBXNativeTarget "mParticle-UserLeap" */; buildPhases = ( DBB01A561DC1478A00A7B188 /* Sources */, DBB01A571DC1478A00A7B188 /* Frameworks */, DBB01A581DC1478A00A7B188 /* Headers */, DBB01A591DC1478A00A7B188 /* Resources */, + DAD96C8824DB31DB0021695F /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( ); - name = "mParticle-Example"; + name = "mParticle-UserLeap"; productName = "mParticle-Example"; - productReference = DBB01A5B1DC1478A00A7B188 /* mParticle_Example.framework */; + productReference = DBB01A5B1DC1478A00A7B188 /* mParticle_UserLeap.framework */; productType = "com.apple.product-type.framework"; }; - FF0BB63A217A84E800B0556C /* mParticle_ExampleTests */ = { + FF0BB63A217A84E800B0556C /* mParticle_UserLeapTests */ = { isa = PBXNativeTarget; - buildConfigurationList = FF0BB645217A84E800B0556C /* Build configuration list for PBXNativeTarget "mParticle_ExampleTests" */; + buildConfigurationList = FF0BB645217A84E800B0556C /* Build configuration list for PBXNativeTarget "mParticle_UserLeapTests" */; buildPhases = ( FF0BB637217A84E800B0556C /* Sources */, FF0BB638217A84E800B0556C /* Frameworks */, - FF0BB639217A84E800B0556C /* Resources */, ); buildRules = ( ); dependencies = ( FF0BB642217A84E800B0556C /* PBXTargetDependency */, ); - name = mParticle_ExampleTests; + name = mParticle_UserLeapTests; productName = mParticle_ExampleTests; - productReference = FF0BB63B217A84E800B0556C /* mParticle_ExampleTests.xctest */; + productReference = FF0BB63B217A84E800B0556C /* mParticle_UserLeapTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -176,11 +195,12 @@ }; }; }; - buildConfigurationList = DBB01A551DC1478A00A7B188 /* Build configuration list for PBXProject "mParticle-Example" */; + buildConfigurationList = DBB01A551DC1478A00A7B188 /* Build configuration list for PBXProject "mParticle-UserLeap" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = DBB01A511DC1478A00A7B188; @@ -188,8 +208,8 @@ projectDirPath = ""; projectRoot = ""; targets = ( - DBB01A5A1DC1478A00A7B188 /* mParticle-Example */, - FF0BB63A217A84E800B0556C /* mParticle_ExampleTests */, + DBB01A5A1DC1478A00A7B188 /* mParticle-UserLeap */, + FF0BB63A217A84E800B0556C /* mParticle_UserLeapTests */, ); }; /* End PBXProject section */ @@ -202,13 +222,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - FF0BB639217A84E800B0556C /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -216,7 +229,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DBB01A691DC1480700A7B188 /* MPKitExample.m in Sources */, + DADFEBB224DB2F0600F96A85 /* MPKitUserLeap.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -224,7 +237,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - FF0BB63E217A84E800B0556C /* mParticle_ExampleTests.m in Sources */, + DADFEBB824DB30C400F96A85 /* mParticle_UserLeapTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -233,7 +246,7 @@ /* Begin PBXTargetDependency section */ FF0BB642217A84E800B0556C /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = DBB01A5A1DC1478A00A7B188 /* mParticle-Example */; + target = DBB01A5A1DC1478A00A7B188 /* mParticle-UserLeap */; targetProxy = FF0BB641217A84E800B0556C /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -242,6 +255,7 @@ DBB01A611DC1478A00A7B188 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -293,6 +307,7 @@ DBB01A621DC1478A00A7B188 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -347,11 +362,11 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); - INFOPLIST_FILE = "mParticle-Example/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/mParticle-UserLeap/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-Example"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-UserLeap"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; }; @@ -369,11 +384,11 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); - INFOPLIST_FILE = "mParticle-Example/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/mParticle-UserLeap/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-Example"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-UserLeap"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; }; @@ -402,12 +417,12 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); GCC_C_LANGUAGE_STANDARD = gnu11; - INFOPLIST_FILE = mParticle_ExampleTests/Info.plist; + INFOPLIST_FILE = mParticle_UserLeapTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(PROJECT_DIR)/Carthage/Build/iOS"; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-ExampleTests"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-UserLeapTests"; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -436,11 +451,11 @@ "$(PROJECT_DIR)/Carthage/Build/iOS", ); GCC_C_LANGUAGE_STANDARD = gnu11; - INFOPLIST_FILE = mParticle_ExampleTests/Info.plist; + INFOPLIST_FILE = mParticle_UserLeapTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(PROJECT_DIR)/Carthage/Build/iOS"; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-ExampleTests"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-UserLeapTests"; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -449,7 +464,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - DBB01A551DC1478A00A7B188 /* Build configuration list for PBXProject "mParticle-Example" */ = { + DBB01A551DC1478A00A7B188 /* Build configuration list for PBXProject "mParticle-UserLeap" */ = { isa = XCConfigurationList; buildConfigurations = ( DBB01A611DC1478A00A7B188 /* Debug */, @@ -458,7 +473,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - DBB01A631DC1478A00A7B188 /* Build configuration list for PBXNativeTarget "mParticle-Example" */ = { + DBB01A631DC1478A00A7B188 /* Build configuration list for PBXNativeTarget "mParticle-UserLeap" */ = { isa = XCConfigurationList; buildConfigurations = ( DBB01A641DC1478A00A7B188 /* Debug */, @@ -467,7 +482,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - FF0BB645217A84E800B0556C /* Build configuration list for PBXNativeTarget "mParticle_ExampleTests" */ = { + FF0BB645217A84E800B0556C /* Build configuration list for PBXNativeTarget "mParticle_UserLeapTests" */ = { isa = XCConfigurationList; buildConfigurations = ( FF0BB643217A84E800B0556C /* Debug */, diff --git a/mParticle-Example.xcodeproj/xcshareddata/xcschemes/mParticle-Example.xcscheme b/mParticle-UserLeap.xcodeproj/xcshareddata/xcschemes/mParticle-Example.xcscheme similarity index 96% rename from mParticle-Example.xcodeproj/xcshareddata/xcschemes/mParticle-Example.xcscheme rename to mParticle-UserLeap.xcodeproj/xcshareddata/xcschemes/mParticle-Example.xcscheme index f71135c..70d4ef8 100644 --- a/mParticle-Example.xcodeproj/xcshareddata/xcschemes/mParticle-Example.xcscheme +++ b/mParticle-UserLeap.xcodeproj/xcshareddata/xcschemes/mParticle-Example.xcscheme @@ -29,8 +29,6 @@ shouldUseLaunchSchemeArgsEnv = "YES"> - - - - +@interface MPKitUserLeap : NSObject @property (nonatomic, strong, nonnull) NSDictionary *configuration; @property (nonatomic, strong, nullable) NSDictionary *launchOptions; diff --git a/mParticle-UserLeap/MPKitUserLeap.m b/mParticle-UserLeap/MPKitUserLeap.m new file mode 100644 index 0000000..9b10dfd --- /dev/null +++ b/mParticle-UserLeap/MPKitUserLeap.m @@ -0,0 +1,219 @@ +#import "MPKitUserLeap.h" + +/* Import your header file here +*/ +#if defined(__has_include) && __has_include() +#import +#import +#else +#import "UserLeapKit.h" +#import "UserLeapKit-Swift.h" +#endif + +@implementation MPKitUserLeap +/* + mParticle will supply a unique kit code for you. Please contact our team +*/ ++ (NSNumber *)kitCode { + return @1169; +} + ++ (void)load { + MPKitRegister *kitRegister = [[MPKitRegister alloc] initWithName:@"UserLeap" className:@"MPKitUserLeap"]; + [MParticle registerExtension:kitRegister]; +} + +- (MPKitExecStatus *)execStatus:(MPKitReturnCode)returnCode { + return [[MPKitExecStatus alloc] initWithSDKCode:self.class.kitCode returnCode:returnCode]; +} + +#pragma mark Kit instance and lifecycle +- (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configuration { + NSString *environmentId = configuration[@"environmentId"]; + if (!environmentId || ![environmentId isKindOfClass:[NSString class]] || environmentId.length == 0) { + return [self execStatus:MPKitReturnCodeRequirementsNotMet]; + } + + _configuration = configuration; + + [self start]; + + return [self execStatus:MPKitReturnCodeSuccess]; +} + +- (void)start { + static dispatch_once_t kitPredicate; + + dispatch_once(&kitPredicate, ^{ + [[UserLeap shared] configureWithEnvironment:self->_configuration[@"environmentId"]]; + + self->_started = YES; + + dispatch_async(dispatch_get_main_queue(), ^{ + NSDictionary *userInfo = @{mParticleKitInstanceKey:[[self class] kitCode]}; + + [[NSNotificationCenter defaultCenter] postNotificationName:mParticleKitDidBecomeActiveNotification + object:nil + userInfo:userInfo]; + }); + }); +} + +- (id const)providerKitInstance { + return [self started] ? UserLeap.shared : nil; +} + +#pragma mark Application + +//we currently don't need to handle any of these + +#pragma mark User attributes + +- (nonnull MPKitExecStatus *)setUserAttribute:(nonnull NSString *)key value:(nonnull id)value { + //only handle numbers and strings + //arrays and dicts will be handled in a later version + if ([value isKindOfClass:[NSNumber class]] || [value isKindOfClass:[NSString class]]) { + [[UserLeap shared] setVisitorAttributeWithKey:key value:[NSString stringWithFormat:@"%@",value]]; + return [self execStatus:MPKitReturnCodeSuccess]; + } + return [self execStatus:MPKitReturnCodeUnavailable]; +} + +- (nonnull MPKitExecStatus *)setUserIdentity:(nullable NSString *)identityString identityType:(MPUserIdentity)identityType { + MPKitReturnCode returnCode; + switch (identityType) { + case MPUserIdentityEmail: + [[UserLeap shared] setEmailAddress:identityString]; + returnCode = MPKitReturnCodeSuccess; + break; + case MPUserIdentityCustomerId: + case MPUserIdentityAlias: + [[UserLeap shared] setUserIdentifier:identityString]; + returnCode = MPKitReturnCodeSuccess; + break; + default: + returnCode = MPKitReturnCodeRequirementsNotMet; + break; + } + return [self execStatus:returnCode]; +} + +- (nonnull MPKitExecStatus *)setUserTag:(nonnull NSString *)tag { + [[UserLeap shared] setVisitorAttributeWithKey:tag value:@"1"]; + return [self execStatus:MPKitReturnCodeSuccess]; +} + +- (nonnull MPKitExecStatus *)onIdentifyComplete:(nonnull FilteredMParticleUser *)user + request:(nonnull FilteredMPIdentityApiRequest *)request { + return [self _handleLogin:user request:request]; +} + +- (nonnull MPKitExecStatus *)onLoginComplete:(nonnull FilteredMParticleUser *)user + request:(nonnull FilteredMPIdentityApiRequest *)request { + return [self _handleLogin:user request:request]; +} + +- (nonnull MPKitExecStatus *)_handleLogin:(nonnull FilteredMParticleUser *)user + request:(nonnull FilteredMPIdentityApiRequest *)request { + if (request.customerId) [[UserLeap shared] setUserIdentifier:request.customerId]; + if (request.email) [[UserLeap shared] setEmailAddress:request.email]; + return [self execStatus:MPKitReturnCodeSuccess]; +} + +- (nonnull MPKitExecStatus *)onModifyComplete:(FilteredMParticleUser *)user + request:(FilteredMPIdentityApiRequest *)request { + if (request.email) [[UserLeap shared] setEmailAddress:request.email]; + return [self execStatus:MPKitReturnCodeSuccess]; +} + +- (nonnull MPKitExecStatus *)onLogoutComplete:(nonnull FilteredMParticleUser *)user + request:(nonnull FilteredMPIdentityApiRequest *)request { + [[UserLeap shared] logout]; + return [self execStatus:MPKitReturnCodeSuccess]; +} + +#pragma mark Events + +NSString *commerceNameFromEvent(MPCommerceEvent *event) { + switch (event.action) { + case MPCommerceEventActionClick: + return @"click"; + case MPCommerceEventActionRefund: + return @"refund"; + case MPCommerceEventActionCheckout: + return @"checkout"; + case MPCommerceEventActionPurchase: + return @"purchase"; + case MPCommerceEventActionViewDetail: + return @"view detail"; + case MPCommerceEventActionAddToCart: + return @"add to cart"; + case MPCommerceEventActionCheckoutOptions: + return @"checkout options"; + case MPCommerceEventActionRemoveFromCart: + return @"remove from cart"; + case MPCommerceEventActionRemoveFromWishlist: + return @"remove from wishlist"; + case MPCommerceEventActionAddToWishList: + return @"add to wishlist"; + default: + break; + } + return nil; +} + +- (nonnull MPKitExecStatus *)logBaseEvent:(MPBaseEvent *)event { + NSString *name = nil; + if ([event isKindOfClass:[MPEvent class]]) name = ((MPEvent *)event).name; + else if ([event isKindOfClass:[MPCommerceEvent class]]) name = commerceNameFromEvent((MPCommerceEvent *)event); + if (!name) return [self execStatus:MPKitReturnCodeUnavailable]; + + BOOL showSurvey = [event.timestamp timeIntervalSinceNow] > -5; + if (event.customAttributes[@"userleap_dont_show_survey"]) showSurvey = NO; + void (^surveyDisplayer)(enum SurveyState state) = showSurvey ? ^void(enum SurveyState state) { + if (state == SurveyStateReady) { + [[UserLeap shared] presentSurveyFrom:[self topViewController]]; + } + } : nil; + [[UserLeap shared] trackWithEventName:name handler:surveyDisplayer]; + return [self execStatus:MPKitReturnCodeSuccess]; +} + +- (nonnull MPKitExecStatus *)logout { + [[UserLeap shared] logout]; + return [self execStatus:MPKitReturnCodeSuccess]; +} + +#pragma mark - Utilities + +- (UIViewController *)topViewController { + return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; +} + +- (UIViewController *)topViewControllerWithRootViewController:(UIViewController *)viewController { + if ([viewController isKindOfClass:[UITabBarController class]]) { + UITabBarController *tabBarController = (UITabBarController *)viewController; + return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; + } else if ([viewController isKindOfClass:[UINavigationController class]]) { + UINavigationController *navContObj = (UINavigationController *)viewController; + return [self topViewControllerWithRootViewController:navContObj.visibleViewController]; + } else if (viewController.presentedViewController && !viewController.presentedViewController.isBeingDismissed) { + UIViewController *presentedViewController = viewController.presentedViewController; + return [self topViewControllerWithRootViewController:presentedViewController]; + } + else { + for (UIView *view in [viewController.view subviews]) + { + id subViewController = [view nextResponder]; + if ( subViewController && [subViewController isKindOfClass:[UIViewController class]]) + { + if ([(UIViewController *)subViewController presentedViewController] && ![subViewController presentedViewController].isBeingDismissed) { + return [self topViewControllerWithRootViewController:[(UIViewController *)subViewController presentedViewController]]; + } + } + } + return viewController; + } +} + +@end diff --git a/mParticle-Example/mParticle_Example.h b/mParticle-UserLeap/mParticle_UserLeap.h similarity index 77% rename from mParticle-Example/mParticle_Example.h rename to mParticle-UserLeap/mParticle_UserLeap.h index 5458d1f..4208c32 100644 --- a/mParticle-Example/mParticle_Example.h +++ b/mParticle-UserLeap/mParticle_UserLeap.h @@ -3,4 +3,4 @@ FOUNDATION_EXPORT double mParticle_ExampleVersionNumber; FOUNDATION_EXPORT const unsigned char mParticle_ExampleVersionString[]; -#import +#import diff --git a/mParticle_ExampleTests/mParticle_ExampleTests.m b/mParticle_ExampleTests/mParticle_ExampleTests.m deleted file mode 100644 index 5baa60f..0000000 --- a/mParticle_ExampleTests/mParticle_ExampleTests.m +++ /dev/null @@ -1,28 +0,0 @@ -#import -#import "MPKitExample.h" - -@interface mParticle_ExampleTests : XCTestCase - -@end - -@implementation mParticle_ExampleTests - -- (void)setUp { - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. -} - -- (void)testModuleID { - XCTAssertEqualObjects([MPKitExample kitCode], @123); -} - -- (void)testStarted { - MPKitExample *exampleKit = [[MPKitExample alloc] init]; - [exampleKit didFinishLaunchingWithConfiguration:@{@"":@"12345"}]; - XCTAssertTrue(exampleKit.started); -} - -@end diff --git a/mParticle_UserLeap.json b/mParticle_UserLeap.json new file mode 100644 index 0000000..cef4525 --- /dev/null +++ b/mParticle_UserLeap.json @@ -0,0 +1,3 @@ +{ + "1.0.0": "https://github.com/UserLeap/userleap-mparticle-ios-kit/releases/download/1.0.0/UserLeap_mParticle.framework.zip" +} \ No newline at end of file diff --git a/mParticle_ExampleTests/Info.plist b/mParticle_UserLeapTests/Info.plist similarity index 100% rename from mParticle_ExampleTests/Info.plist rename to mParticle_UserLeapTests/Info.plist diff --git a/mParticle_UserLeapTests/mParticle_UserLeapTests.m b/mParticle_UserLeapTests/mParticle_UserLeapTests.m new file mode 100644 index 0000000..bd9a619 --- /dev/null +++ b/mParticle_UserLeapTests/mParticle_UserLeapTests.m @@ -0,0 +1,108 @@ +#import +#import "MPKitUserLeap.h" + +@interface mParticle_UserLeapTests : XCTestCase + +@end + +@implementation mParticle_UserLeapTests + +static MPKitUserLeap *kit; + +- (void)setUp { + if (!kit) { + kit = [[MPKitUserLeap alloc] init]; + [kit didFinishLaunchingWithConfiguration:@{@"environmentId":@"someEnvironmentId"}]; + } +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +#pragma mark - Tests + +- (void)testModuleID { + XCTAssertEqualObjects([MPKitUserLeap kitCode], @1169); +} + +- (void)testStarted { + XCTestExpectation *exp = [[XCTestExpectation alloc] initWithDescription:@"desc"]; + NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.01 repeats:YES block:^(NSTimer * _Nonnull timer) { + if (kit.started) [exp fulfill]; + }]; + XCTWaiterResult result = [XCTWaiter waitForExpectations:@[exp] timeout:5]; + XCTAssertEqual(result, XCTWaiterResultCompleted); + XCTAssertTrue(kit.started); + XCTAssertNotNil(kit.providerKitInstance); + [timer invalidate]; +} + +- (void)testInvalidEnvironmentIdTypeReturnsFalse { + MPKitUserLeap *invalidKit = [[MPKitUserLeap alloc] init]; + MPKitExecStatus *status = [invalidKit didFinishLaunchingWithConfiguration:@{@"_environmentId":@"thekeyisinvalid"}]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeRequirementsNotMet); +} + +- (void)testSetAttributesWithStringValueReturnsSuccess { + MPKitExecStatus *status = [kit setUserAttribute:@"key" value:@"value"]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testSetAttributesWithNumberValueReturnsSuccess { + MPKitExecStatus *status = [kit setUserAttribute:@"key" value:@1]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testSetAttributesWithArrayReturnsFalse { + MPKitExecStatus *status = [kit setUserAttribute:@"key" value:@[@"value"]]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeUnavailable); +} + +- (void)testSetAttributesWithDictionaryReturnsFalse { + MPKitExecStatus *status = [kit setUserAttribute:@"key" value:@{@"value":@1}]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeUnavailable); +} + +- (void)testSetEmailAddressReturnsTrue { + MPKitExecStatus *status = [kit setUserIdentity:@"someEmail@gmail.com" identityType:MPUserIdentityEmail]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testSetCustomerIdReturnsTrue { + MPKitExecStatus *status = [kit setUserIdentity:@"anything" identityType:MPUserIdentityCustomerId]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testSetUserTagReturnsTrue { + MPKitExecStatus *status = [kit setUserTag:@"something"]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testLogEventReturnsSuccess { + MPBaseEvent *event = [[MPBaseEvent alloc] initWithEventType:MPEventTypeAddToCart]; + event.messageType = MPMessageTypeEvent; + MPKitExecStatus *status = [kit logBaseEvent:event]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testLogCommerceEventReturnsSuccess { + MPBaseEvent *event = [[MPBaseEvent alloc] initWithEventType:MPEventTypeAddToCart]; + event.messageType = MPMessageTypeCommerceEvent; + MPKitExecStatus *status = [kit logBaseEvent:event]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +- (void)testLogOtherEventReturnsUnsupported { + MPBaseEvent *event = [[MPBaseEvent alloc] initWithEventType:MPEventTypeAddToCart]; + event.messageType = MPMessageTypeMedia; + MPKitExecStatus *status = [kit logBaseEvent:event]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeUnavailable); +} + +- (void)testLogoutReturnsSuccess { + MPKitExecStatus *status = [kit logout]; + XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess); +} + +@end