fix(iam): prevent crash when dismissing IAM during view hierarchy changes#1641
Merged
fix(iam): prevent crash when dismissing IAM during view hierarchy changes#1641
Conversation
…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.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
fadi-george
approved these changes
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:YESwas 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:

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.viewin these cases.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is