Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix set opt out for kits #300

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
39 changes: 39 additions & 0 deletions UnitTests/MPKitContainerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,45 @@ - (void)testAttemptToLogBaseEventMediaTypeToKit {
[kitWrapperMock verifyWithDelay:5.0];
}

- (void)testAttemptToSetOptOutToKitTrue {
MPKitContainer *localKitContainer = [[MPKitContainer alloc] init];

MPKitRegister *kitRegister = [[MPKitRegister alloc] initWithName:@"AppsFlyer" className:@"MPKitAppsFlyerTest"];
id kitWrapperMock = OCMProtocolMock(@protocol(MPKitProtocol));
id kitRegisterMock = OCMPartialMock(kitRegister);
OCMStub([kitRegisterMock wrapperInstance]).andReturn(kitWrapperMock);
MPKitFilter *kitFilter = [kitContainer filter:kitRegisterMock forEvent:nil selector:@selector(setOptOut:)];

[(id <MPKitProtocol>)[kitWrapperMock expect] setOptOut:YES];

MPForwardQueueParameters *optOutParameters = [[MPForwardQueueParameters alloc] init];
[optOutParameters addParameter:@(1)];

[localKitContainer attemptToLogEventToKit:kitRegister kitFilter:kitFilter selector:@selector(setOptOut:) parameters:optOutParameters messageType:MPMessageTypeOptOut userInfo:@{@"state":@(1)}];

[kitWrapperMock verifyWithDelay:5.0];
}

- (void)testAttemptToSetOptOutToKitFalse {
MPKitContainer *localKitContainer = [[MPKitContainer alloc] init];

MPKitRegister *kitRegister = [[MPKitRegister alloc] initWithName:@"AppsFlyer" className:@"MPKitAppsFlyerTest"];
id kitWrapperMock = OCMProtocolMock(@protocol(MPKitProtocol));
id kitRegisterMock = OCMPartialMock(kitRegister);
OCMStub([kitRegisterMock wrapperInstance]).andReturn(kitWrapperMock);
MPKitFilter *kitFilter = [kitContainer filter:kitRegisterMock forEvent:nil selector:@selector(setOptOut:)];

[(id <MPKitProtocol>)[kitWrapperMock expect] setOptOut:FALSE];

MPForwardQueueParameters *optOutParameters = [[MPForwardQueueParameters alloc] init];
NSNumber *optOutStatus = @(0);
[optOutParameters addParameter:optOutStatus];

[localKitContainer attemptToLogEventToKit:kitRegister kitFilter:kitFilter selector:@selector(setOptOut:) parameters:optOutParameters messageType:MPMessageTypeOptOut userInfo:@{@"state":optOutStatus}];

[kitWrapperMock verifyWithDelay:5.0];
}

- (void)testAttemptToLegacyOpenURLToKit {
MPKitContainer *localKitContainer = [[MPKitContainer alloc] init];
SEL selector = @selector(openURL:sourceApplication:annotation:);
Expand Down
6 changes: 6 additions & 0 deletions mParticle-Apple-SDK/Kits/MPKitContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,12 @@ - (void)attemptToLogEventToKit:(id<MPExtensionKitProtocol>)kitRegister kitFilter
MPATTAuthorizationStatus status = (MPATTAuthorizationStatus)[parameters[0] unsignedIntValue];
NSNumber *timestamp = [parameters[1] isKindOfClass:[NSNumber class]] ? (NSNumber*)parameters[1] : nil;
execStatus = [kitRegister.wrapperInstance setATTStatus:status withATTStatusTimestampMillis:timestamp];
} else if (selector == @selector(setOptOut:)) {
if (parameters.count == 1 && [parameters[0] boolValue]) {
execStatus = [kitRegister.wrapperInstance setOptOut:true];
} else {
execStatus = [kitRegister.wrapperInstance setOptOut:false];
}
BrandonStalnaker marked this conversation as resolved.
Show resolved Hide resolved
} else if (parameters.count == 3) {
typedef MPKitExecStatus *(*send_type)(id, SEL, id, id, id);
send_type func = (send_type)objc_msgSend;
Expand Down
5 changes: 4 additions & 1 deletion mParticle-Apple-SDK/mParticle.m
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,12 @@ - (void)setOptOut:(BOOL)optOut {
self.stateMachine.optOut = optOut;

// Forwarding calls to kits
MPForwardQueueParameters *optOutParameters = [[MPForwardQueueParameters alloc] init];
[optOutParameters addParameter:@(optOut)];

[[MParticle sharedInstance].kitContainer forwardSDKCall:@selector(setOptOut:)
event:nil
parameters:nil
parameters:optOutParameters
messageType:MPMessageTypeOptOut
userInfo:@{kMPStateKey:@(optOut)}
];
Expand Down
Loading