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 Crash for In App Message clicks with no id #1248

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSMessagingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ - (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppM
// Handles body, button, or image clicks
if (![self isClickAvailable:message withClickId:clickId])
return;

if (!clickId) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"sendClickRESTCall:withAction: call could not be made because the click action does not have an id."];
return;
}
// Add clickId to clickedClickIds
[self.clickedClickIds addObject:clickId];
// Track clickId per IAM
Expand Down
26 changes: 26 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,32 @@ - (void)testIAMClickedLaunchesAPIRequest {
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequestType, NSStringFromClass([OSRequestInAppMessageClicked class]));
}

- (void)testIAMClickWithNoIDLogsError {
let message = [OSInAppMessageTestHelper testMessageJsonWithTriggerPropertyName:OS_DYNAMIC_TRIGGER_KIND_SESSION_TIME withId:@"test_id1" withOperator:OSTriggerOperatorTypeLessThan withValue:@10.0];

let registrationResponse = [OSInAppMessageTestHelper testRegistrationJsonWithMessages:@[message]];

// the trigger should immediately evaluate to true and should
// be shown once the SDK is fully initialized.
[OneSignalClientOverrider setMockResponseForRequest:NSStringFromClass([OSRequestRegisterUser class]) withResponse:registrationResponse];

[UnitTestCommonMethods initOneSignal_andThreadWait];

// the message should now be displayed
// simulate a button press (action) on the inapp message with a nil id
let action = [OSInAppMessageAction new];
action.clickType = @"button";
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
action.clickId = nil;
#pragma GCC diagnostic pop
let testMessage = [OSInAppMessageInternal instanceWithJson:message];

[OSMessagingController.sharedInstance messageViewDidSelectAction:testMessage withAction:action];
// The action should not send a request due to the nil id but it should not crash
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequestType, NSStringFromClass([OSRequestRegisterUser class]));
}

- (void)testIAMClickedLaunchesOutcomeAPIRequest {
[self setOutcomesParamsEnabled];

Expand Down