Skip to content

Commit 1c97103

Browse files
authored
fix(iam): prevent crash when dismissing IAM during view hierarchy changes (#1641)
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.
1 parent 24c8745 commit 1c97103

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,14 @@ - (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {
516516
if (self.dismissalTimer)
517517
[self.dismissalTimer invalidate];
518518

519-
// If the rendering event never occurs any constraints being adjusted for dismissal will be nil
520-
// and we should bypass dismissal adjustments and animations and skip straight to the OSMessagingController callback for dismissing
521-
if (!self.didPageRenderingComplete) {
519+
// Return early and skip constraint adjustments/animations if:
520+
// - Page rendering never completed (constraints would be nil)
521+
// - messageView is not valid or not a direct subview of self.view (prevents crashes when
522+
// dismissal is triggered while the view hierarchy is in an inconsistent state)
523+
if (!self.didPageRenderingComplete ||
524+
!self.messageView ||
525+
self.messageView.superview != self.view)
526+
{
522527
[self dismissViewControllerAnimated:false completion:nil];
523528
[self.delegate messageViewControllerWasDismissed:self.message displayed:NO];
524529
return;

0 commit comments

Comments
 (0)