From a1259b017af0332ae06d3d1fad531d88d8f2a32f Mon Sep 17 00:00:00 2001 From: Nan Date: Mon, 2 Feb 2026 09:10:48 -0800 Subject: [PATCH] fix(iam): prevent crash when dismissing IAM during view hierarchy changes Fix crash in -[OSInAppMessageViewController dismissCurrentInAppMessage:withVelocity:] The crash occurred when setInAppMessagingPaused:YES was called while the IAM's view hierarchy was in an inconsistent state (e.g., during orientation change). The code attempted to modify Auto Layout constraints on a messageView that was no longer a subview of self.view, causing an NSLayoutConstraint exception. Added a guard check to return out early if messageView.superview != self.view. --- .../UI/OSInAppMessageViewController.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m index 7a3f75707..561dae491 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m +++ b/iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m @@ -516,9 +516,14 @@ - (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity { if (self.dismissalTimer) [self.dismissalTimer invalidate]; - // If the rendering event never occurs any constraints being adjusted for dismissal will be nil - // and we should bypass dismissal adjustments and animations and skip straight to the OSMessagingController callback for dismissing - if (!self.didPageRenderingComplete) { + // Return early and skip constraint adjustments/animations if: + // - Page rendering never completed (constraints would be nil) + // - messageView is not valid or not a direct subview of self.view (prevents crashes when + // dismissal is triggered while the view hierarchy is in an inconsistent state) + if (!self.didPageRenderingComplete || + !self.messageView || + self.messageView.superview != self.view) + { [self dismissViewControllerAnimated:false completion:nil]; [self.delegate messageViewControllerWasDismissed:self.message displayed:NO]; return;