Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 14 additions & 37 deletions UnitTests/MPRoktTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@ - (void)testSelectPlacementsSimpleWithValidParameters {

// Set up expectations for kit container
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for async operation"];
SEL roktSelector = @selector(executeWithViewName:attributes:placements:onLoad:onUnLoad:onShouldShowLoadingIndicator:onShouldHideLoadingIndicator:onEmbeddedSizeChange:filteredUser:);
SEL roktSelector = @selector(executeWithViewName:attributes:placements:callbacks:filteredUser:);
OCMExpect([mockContainer forwardSDKCall:roktSelector
event:nil
parameters:[OCMArg checkWithBlock:^BOOL(MPForwardQueueParameters *params) {
XCTAssertEqualObjects(params[0], viewName);
XCTAssertEqualObjects(params[1], attributes);
XCTAssertNil(params[2]);
XCTAssertNil(params[3]);
XCTAssertNil(params[4]);
XCTAssertNil(params[5]);
XCTAssertNil(params[6]);
XCTAssertNil(params[7]);
return true;
}]
messageType:MPMessageTypeEvent
Expand Down Expand Up @@ -88,26 +84,23 @@ - (void)testSelectPlacementsExpandedWithValidParameters {
NSDictionary *finalAttributes = @{@"key": @"value", @"sandbox": @"true"};
MPRoktEmbeddedView *exampleView = [[MPRoktEmbeddedView alloc] initWithFrame:CGRectZero];
NSDictionary *placements = @{@"placement": exampleView};
void (^onLoad)(void) = ^{};
void (^onUnLoad)(void) = ^{};
void (^onShouldShowLoadingIndicator)(void) = ^{};
void (^onShouldHideLoadingIndicator)(void) = ^{};
void (^onEmbeddedSizeChange)(NSString *, CGFloat) = ^(NSString *p, CGFloat s){};
MPRoktEventCallback *exampleCallbacks = [[MPRoktEventCallback alloc] init];
exampleCallbacks.onLoad = ^{};
exampleCallbacks.onUnLoad = ^{};
exampleCallbacks.onShouldShowLoadingIndicator = ^{};
exampleCallbacks.onShouldHideLoadingIndicator = ^{};
exampleCallbacks.onEmbeddedSizeChange = ^(NSString *p, CGFloat s){};

// Set up expectations for kit container
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for async operation"];
SEL roktSelector = @selector(executeWithViewName:attributes:placements:onLoad:onUnLoad:onShouldShowLoadingIndicator:onShouldHideLoadingIndicator:onEmbeddedSizeChange:filteredUser:);
SEL roktSelector = @selector(executeWithViewName:attributes:placements:callbacks:filteredUser:);
OCMExpect([mockContainer forwardSDKCall:roktSelector
event:nil
parameters:[OCMArg checkWithBlock:^BOOL(MPForwardQueueParameters *params) {
XCTAssertEqualObjects(params[0], viewName);
XCTAssertEqualObjects(params[1], finalAttributes);
XCTAssertEqualObjects(params[2], placements);
XCTAssertTrue(params[3] != nil);
XCTAssertTrue(params[4] != nil);
XCTAssertTrue(params[5] != nil);
XCTAssertTrue(params[6] != nil);
XCTAssertTrue(params[7] != nil);
XCTAssertEqualObjects(params[3], exampleCallbacks);
return true;
}]
messageType:MPMessageTypeEvent
Expand All @@ -119,11 +112,7 @@ - (void)testSelectPlacementsExpandedWithValidParameters {
[self.rokt selectPlacements:viewName
attributes:attributes
placements:placements
onLoad:onLoad
onUnLoad:onUnLoad
onShouldShowLoadingIndicator:onShouldShowLoadingIndicator
onShouldHideLoadingIndicator:onShouldHideLoadingIndicator
onEmbeddedSizeChange:onEmbeddedSizeChange];
callbacks:exampleCallbacks];

// Wait for async operation
[self waitForExpectationsWithTimeout:1.0 handler:nil];
Expand All @@ -147,16 +136,12 @@ - (void)testSelectPlacementsExpandedWithNilParameters {
[self.rokt selectPlacements:viewName
attributes:nil
placements:nil
onLoad:nil
onUnLoad:nil
onShouldShowLoadingIndicator:nil
onShouldHideLoadingIndicator:nil
onEmbeddedSizeChange:nil];
callbacks:nil];

// Wait for async operation
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for async operation"];

SEL roktSelector = @selector(executeWithViewName:attributes:placements:onLoad:onUnLoad:onShouldShowLoadingIndicator:onShouldHideLoadingIndicator:onEmbeddedSizeChange:filteredUser:);
SEL roktSelector = @selector(executeWithViewName:attributes:placements:callbacks:filteredUser:);
NSDictionary *finalAttributes = @{@"sandbox": @"true"};

OCMExpect([mockContainer forwardSDKCall:roktSelector
Expand All @@ -166,10 +151,6 @@ - (void)testSelectPlacementsExpandedWithNilParameters {
XCTAssertEqualObjects(params[1], finalAttributes);
XCTAssertNil(params[2]);
XCTAssertNil(params[3]);
XCTAssertNil(params[4]);
XCTAssertNil(params[5]);
XCTAssertNil(params[6]);
XCTAssertNil(params[7]);
return true;
}]
messageType:MPMessageTypeEvent
Expand Down Expand Up @@ -199,18 +180,14 @@ - (void)testSelectPlacementsSimpleWithMapping {

// Set up expectations for kit container
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for async operation"];
SEL roktSelector = @selector(executeWithViewName:attributes:placements:onLoad:onUnLoad:onShouldShowLoadingIndicator:onShouldHideLoadingIndicator:onEmbeddedSizeChange:filteredUser:);
SEL roktSelector = @selector(executeWithViewName:attributes:placements:callbacks:filteredUser:);
OCMExpect([mockContainer forwardSDKCall:roktSelector
event:nil
parameters:[OCMArg checkWithBlock:^BOOL(MPForwardQueueParameters *params) {
XCTAssertEqualObjects(params[0], viewName);
XCTAssertEqualObjects(params[1], mappedAttributes);
XCTAssertNil(params[2]);
XCTAssertNil(params[3]);
XCTAssertNil(params[4]);
XCTAssertNil(params[5]);
XCTAssertNil(params[6]);
XCTAssertNil(params[7]);
return true;
}]
messageType:MPMessageTypeEvent
Expand All @@ -237,7 +214,7 @@ - (void)testSelectPlacementsSimpleWithNilMapping {
[[[mockInstance stub] andReturn:mockContainer] kitContainer_PRIVATE];
[[[mockInstance stub] andReturn:mockInstance] sharedInstance];

SEL roktSelector = @selector(executeWithViewName:attributes:placements:onLoad:onUnLoad:onShouldShowLoadingIndicator:onShouldHideLoadingIndicator:onEmbeddedSizeChange:filteredUser:);
SEL roktSelector = @selector(executeWithViewName:attributes:placements:callbacks:filteredUser:);
OCMReject([mockContainer forwardSDKCall:roktSelector
event:[OCMArg any]
parameters:[OCMArg any]
Expand Down
12 changes: 12 additions & 0 deletions mParticle-Apple-SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@
53E20DC82CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53E20DC62CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift */; };
53FDD1BD2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; };
53FDD1BE2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; };
7E0387812DB913D2003B7D5E /* MPRokt.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E03877F2DB913D2003B7D5E /* MPRokt.h */; settings = {ATTRIBUTES = (Public, ); }; };
7E0387822DB913D2003B7D5E /* MPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E0387802DB913D2003B7D5E /* MPRokt.m */; };
7E0387832DB913D2003B7D5E /* MPRokt.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E03877F2DB913D2003B7D5E /* MPRokt.h */; settings = {ATTRIBUTES = (Public, ); }; };
7E0387842DB913D2003B7D5E /* MPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E0387802DB913D2003B7D5E /* MPRokt.m */; };
7E15B2062D94617900C1FF3E /* MPRoktTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E15B2052D94617900C1FF3E /* MPRoktTests.m */; };
7E15B2072D94617900C1FF3E /* MPRoktTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E15B2052D94617900C1FF3E /* MPRoktTests.m */; };
D30CD0CB2CFF5FB100F5148A /* MPStateMachine.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0629CDFB1F00E7489F /* MPStateMachine.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -763,6 +767,8 @@
53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPSideloadedKit.swift; sourceTree = "<group>"; };
53E20DC62CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSArray+MPCaseInsensitiveTests.swift"; sourceTree = "<group>"; };
53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIHasher.swift; sourceTree = "<group>"; };
7E03877F2DB913D2003B7D5E /* MPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPRokt.h; sourceTree = "<group>"; };
7E0387802DB913D2003B7D5E /* MPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPRokt.m; sourceTree = "<group>"; };
7E15B2052D94617900C1FF3E /* MPRoktTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPRoktTests.m; sourceTree = "<group>"; };
D33C8B312B8510C20012EDFD /* MPAudience.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPAudience.h; sourceTree = "<group>"; };
D33C8B322B8510C20012EDFD /* MPAudience.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPAudience.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -851,6 +857,7 @@
children = (
53A79C2229CDFB4800E7489F /* Include */,
53A79B3629CDFB1F00E7489F /* mParticle.m */,
7E0387802DB913D2003B7D5E /* MPRokt.m */,
53A79AF429CDFB1F00E7489F /* MPBackendController.m */,
53A79AD029CDFB1F00E7489F /* MPEnums.m */,
53A79ACF29CDFB1F00E7489F /* MPIConstants.h */,
Expand Down Expand Up @@ -1168,6 +1175,7 @@
53A79B3429CDFB1F00E7489F /* MPNotificationController.h */,
53A79AA329CDFB1E00E7489F /* MPBackendController.h */,
53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */,
7E03877F2DB913D2003B7D5E /* MPRokt.h */,
);
path = Include;
sourceTree = "<group>";
Expand Down Expand Up @@ -1326,6 +1334,7 @@
53A79B9929CDFB2000E7489F /* MPIConstants.h in Headers */,
53A79B7129CDFB2000E7489F /* MPBackendController.h in Headers */,
53A79B7929CDFB2000E7489F /* MPConnectorResponseProtocol.h in Headers */,
7E0387832DB913D2003B7D5E /* MPRokt.h in Headers */,
53A79B7C29CDFB2000E7489F /* MPConnectorFactoryProtocol.h in Headers */,
53A79C1D29CDFB2100E7489F /* MPKitConfiguration.h in Headers */,
53A79B7D29CDFB2000E7489F /* MPNetworkCommunication.h in Headers */,
Expand Down Expand Up @@ -1414,6 +1423,7 @@
53A79D2A29CE23F700E7489F /* MPAppDelegateProxy.h in Headers */,
53A79D2C29CE23F700E7489F /* MPIConstants.h in Headers */,
53A79D2E29CE23F700E7489F /* MPBackendController.h in Headers */,
7E0387812DB913D2003B7D5E /* MPRokt.h in Headers */,
53A79D3029CE23F700E7489F /* MPConnectorResponseProtocol.h in Headers */,
53A79D3229CE23F700E7489F /* MPConnectorFactoryProtocol.h in Headers */,
53A79D3329CE23F700E7489F /* MPNetworkCommunication.h in Headers */,
Expand Down Expand Up @@ -1765,6 +1775,7 @@
53A79BF829CDFB2000E7489F /* MPNotificationController.m in Sources */,
53A79C0829CDFB2100E7489F /* MPEvent.m in Sources */,
53A79B6729CDFB2000E7489F /* MPAliasResponse.m in Sources */,
7E0387842DB913D2003B7D5E /* MPRokt.m in Sources */,
534C11B72D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */,
D342860F2D419CB800FEC2C8 /* MPUploadSettings.swift in Sources */,
53A79C1229CDFB2100E7489F /* MPKitFilter.m in Sources */,
Expand Down Expand Up @@ -1938,6 +1949,7 @@
53A79DA929CE23F700E7489F /* MPAppNotificationHandler.m in Sources */,
53A79DAA29CE23F700E7489F /* MPNotificationController.m in Sources */,
53A79DAB29CE23F700E7489F /* MPEvent.m in Sources */,
7E0387822DB913D2003B7D5E /* MPRokt.m in Sources */,
534C11B62D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */,
D34286102D419CB800FEC2C8 /* MPUploadSettings.swift in Sources */,
53A79DAD29CE23F700E7489F /* MPAliasResponse.m in Sources */,
Expand Down
8 changes: 3 additions & 5 deletions mParticle-Apple-SDK/Include/MPKitProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@class FilteredMParticleUser;
@class FilteredMPIdentityApiRequest;
@class MPRoktEmbeddedView;
@class MPRoktEventCallback;

#if TARGET_OS_IOS == 1 && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@class UNUserNotificationCenter;
Expand Down Expand Up @@ -138,12 +139,9 @@
- (nonnull MPKitExecStatus *)executeWithViewName:(NSString * _Nullable)viewName
attributes:(NSDictionary<NSString *, NSString *> * _Nonnull)attributes
placements:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)placements
onLoad:(void (^ _Nullable)(void))onLoad
onUnLoad:(void (^ _Nullable)(void))onUnLoad
onShouldShowLoadingIndicator:(void (^ _Nullable)(void))onShouldShowLoadingIndicator
onShouldHideLoadingIndicator:(void (^ _Nullable)(void))onShouldHideLoadingIndicator
onEmbeddedSizeChange:(void (^ _Nullable)(NSString * _Nonnull, CGFloat))onEmbeddedSizeChange
callbacks:(MPRoktEventCallback * _Nullable)callbacks
filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser;

@end

#endif
35 changes: 35 additions & 0 deletions mParticle-Apple-SDK/Include/MPRokt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// MPRokt.h
// mParticle-Apple-SDK
//
// Created by Brandon Stalnaker on 4/22/25.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MPRoktEventCallback : NSObject

@property (nonatomic, copy, nullable) void (^onLoad)(void);
@property (nonatomic, copy, nullable) void (^onUnLoad)(void);
@property (nonatomic, copy, nullable) void (^onShouldShowLoadingIndicator)(void);
@property (nonatomic, copy, nullable) void (^onShouldHideLoadingIndicator)(void);
@property (nonatomic, copy, nullable) void (^onEmbeddedSizeChange)(NSString * _Nonnull, CGFloat);

@end

@interface MPRoktEmbeddedView : UIView

@end

@interface MPRokt : NSObject

- (void)selectPlacements:(NSString *_Nonnull)identifier
attributes:(NSDictionary<NSString *, NSString *> * _Nullable)attributes;

- (void)selectPlacements:(NSString *_Nonnull)identifier
attributes:(NSDictionary<NSString *, NSString *> * _Nullable)attributes
placements:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)placements
callbacks:(MPRoktEventCallback * _Nullable)roktEventCallback;

@end
21 changes: 1 addition & 20 deletions mParticle-Apple-SDK/Include/mParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#import "MPNotificationController.h"
#import "MPNetworkCommunication.h"
#import "MPPersistenceController.h"
#import "MPRokt.h"

#if TARGET_OS_IOS == 1
#ifndef MPARTICLE_LOCATION_DISABLE
Expand Down Expand Up @@ -85,26 +86,6 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface MPRoktEmbeddedView : UIView

@end

@interface MPRokt : NSObject

- (void)selectPlacements:(NSString *)identifier
attributes:(NSDictionary<NSString *, NSString *> * _Nullable)attributes;

- (void)selectPlacements:(NSString *)identifier
attributes:(NSDictionary<NSString *, NSString *> * _Nullable)attributes
placements:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)placements
onLoad:(void (^ _Nullable)(void))onLoad
onUnLoad:(void (^ _Nullable)(void))onUnLoad
onShouldShowLoadingIndicator:(void (^ _Nullable)(void))onShouldShowLoadingIndicator
onShouldHideLoadingIndicator:(void (^ _Nullable)(void))onShouldHideLoadingIndicator
onEmbeddedSizeChange:(void (^ _Nullable)(NSString * _Nonnull, CGFloat))onEmbeddedSizeChange;

@end

/**
Allows you to override the default HTTPS hosts and certificates used by the SDK.
*/
Expand Down
8 changes: 2 additions & 6 deletions mParticle-Apple-SDK/Kits/MPKitContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2305,19 +2305,15 @@ - (void)attemptToLogEventToKit:(id<MPExtensionKitProtocol>)kitRegister kitFilter
return;
}
execStatus = [kitRegister.wrapperInstance logEvent:((MPEvent *)kitFilter.forwardEvent)];
} else if (selector == @selector(executeWithViewName:attributes:placements:onLoad:onUnLoad:onShouldShowLoadingIndicator:onShouldHideLoadingIndicator:onEmbeddedSizeChange:filteredUser:)) {
} else if (selector == @selector(executeWithViewName:attributes:placements:callbacks:filteredUser:)) {
if (kitFilter.shouldFilter) {
return;
}
FilteredMParticleUser *filteredUser = [[FilteredMParticleUser alloc] initWithMParticleUser:[[[MParticle sharedInstance] identity] currentUser] kitConfiguration:self.kitConfigurations[kitRegister.code]];
execStatus = [kitRegister.wrapperInstance executeWithViewName:parameters[0]
attributes:parameters[1]
placements:parameters[2]
onLoad:parameters[3]
onUnLoad:parameters[4]
onShouldShowLoadingIndicator:parameters[5]
onShouldHideLoadingIndicator:parameters[6]
onEmbeddedSizeChange:parameters[7]
callbacks:parameters[3]
filteredUser:filteredUser];
} else if (selector == @selector(logScreen:)) {
if (!kitFilter.forwardEvent || ![kitFilter.forwardEvent isKindOfClass:[MPEvent class]]) {
Expand Down
Loading