Skip to content

fix(iam): prevent crash when dismissing IAM during view hierarchy changes#1641

Merged
nan-li merged 1 commit intomainfrom
fix/iam_pausing_view_crash
Feb 3, 2026
Merged

fix(iam): prevent crash when dismissing IAM during view hierarchy changes#1641
nan-li merged 1 commit intomainfrom
fix/iam_pausing_view_crash

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented Feb 2, 2026

Description

One Line Summary

Prevent crash when dismissing IAM during view hierarchy changes, when IAMs get paused.

Details

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). Due to the async dispatch, there's a race condition where the messageView could be removed from the view hierarchy or in an inconsistent state before the dismissal code runs. 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.

Motivation

Fix crash reported:
crash rerpot

Scope

Dismissing IAM view when pausing IAM

Testing

Unit testing

None, hard to test views

Manual testing

iOS 18.5 simulator, I was able reproduce on occasion by calling this code while rotating device quickly and seeing that self.messageView.superview != self.view in these cases.

// Trigger IAM
[OneSignal.InAppMessages addTrigger:@"fruit" withValue:@"apple"];

// Immediately pause while rotation is happening
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [OneSignal.InAppMessages paused:true];
});

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

…nges

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.
@nan-li nan-li requested a review from a team February 2, 2026 17:18
@claude
Copy link

claude bot commented Feb 2, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants