diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m index f7330e89e..072fbd13d 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m @@ -931,6 +931,10 @@ - (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 diff --git a/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m b/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m index 5a6674cc4..5b1ae9065 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m +++ b/iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m @@ -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];