Skip to content

Commit 178da93

Browse files
authored
Merge pull request #1248 from OneSignal/fix/crash_in_iam_html
Fix Crash for In App Message clicks with no id
2 parents 0890af2 + 54af1ba commit 178da93

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

iOS_SDK/OneSignalSDK/Source/OSMessagingController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ - (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppM
793793
// Handles body, button, or image clicks
794794
if (![self isClickAvailable:message withClickId:clickId])
795795
return;
796+
797+
if (!clickId) {
798+
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"sendClickRESTCall:withAction: call could not be made because the click action does not have an id."];
799+
return;
800+
}
796801
// Add clickId to clickedClickIds
797802
[self.clickedClickIds addObject:clickId];
798803
// Track clickId per IAM

iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,32 @@ - (void)testIAMClickedLaunchesAPIRequest {
833833
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequestType, NSStringFromClass([OSRequestInAppMessageClicked class]));
834834
}
835835

836+
- (void)testIAMClickWithNoIDLogsError {
837+
let message = [OSInAppMessageTestHelper testMessageJsonWithTriggerPropertyName:OS_DYNAMIC_TRIGGER_KIND_SESSION_TIME withId:@"test_id1" withOperator:OSTriggerOperatorTypeLessThan withValue:@10.0];
838+
839+
let registrationResponse = [OSInAppMessageTestHelper testRegistrationJsonWithMessages:@[message]];
840+
841+
// the trigger should immediately evaluate to true and should
842+
// be shown once the SDK is fully initialized.
843+
[OneSignalClientOverrider setMockResponseForRequest:NSStringFromClass([OSRequestRegisterUser class]) withResponse:registrationResponse];
844+
845+
[UnitTestCommonMethods initOneSignal_andThreadWait];
846+
847+
// the message should now be displayed
848+
// simulate a button press (action) on the inapp message with a nil id
849+
let action = [OSInAppMessageAction new];
850+
action.clickType = @"button";
851+
#pragma GCC diagnostic push
852+
#pragma GCC diagnostic ignored "-Wnonnull"
853+
action.clickId = nil;
854+
#pragma GCC diagnostic pop
855+
let testMessage = [OSInAppMessageInternal instanceWithJson:message];
856+
857+
[OSMessagingController.sharedInstance messageViewDidSelectAction:testMessage withAction:action];
858+
// The action should not send a request due to the nil id but it should not crash
859+
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequestType, NSStringFromClass([OSRequestRegisterUser class]));
860+
}
861+
836862
- (void)testIAMClickedLaunchesOutcomeAPIRequest {
837863
[self setOutcomesParamsEnabled];
838864

0 commit comments

Comments
 (0)