Changing presentation style crashes app

Hello! I've been digging into this for a little bit now, and am hitting something of a wall. Our app is crashing occasionally, and googling the crash yields literally 0 results.

Tl;dr: Something related to adaptivePresentationStyle(for:traitCollection:) is resulting in our app crashing.

Context

In our app, we have a custom UIPresentationController that we use to present a small sheet of content overlaying other app content - similar to a UISheetPresentationController with a medium-ish size. So we have a custom UIViewController to present, and it conforms to the UIAdaptivePresentationControllerDelegate protocol. We also have custom present and dismiss animators.

The crash

However, we seem to be running into a really odd crash. I've attached a crash report as well, but here's what one sees in xcode on reproducing the crash:

The _computeToEndFrameForCurrentTransition block is nil inside the _transitionViewForCurrentTransition block, value of outerStrongSelf currently : <XxxYyyyyyZzz.PopupPresentationController: 0x12d017a40>. This most likely indicates that an adaptation is happening after a transtion cleared out _computeToEndFrameForCurrentTransition. Captured debug information outside block: presentationController : <XxxYyyyyyZzz.PopupPresentationController: 0x12d017a40> presentedViewController : <XxxYyyyyyZzz.SomeViewController: 0x12d03a690> presentingViewController : <UINavigationController: 0x12a817400>

Whenever we present one of these view controllers, things work just fine. When we try to present another one though, if someone is aggressively changing the phone orientation, the app crashes. This crash occurs somewhere in between dismissing the old VC and presenting the new one. It occurs before I ever hit any breakpoints in the "present" animator for the second view controller.

I've narrowed things down a bit, and by commenting out our implementation of adaptivePresentationStyle(for:traitCollection:), the crash can't be reproduced anymore. The downside there being that the app no longer functions how we want it to. Our definition of that function (which causes crashes) looks like this:

public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        guard forceUsingFullScreenIfCompact else {
            return .none
        }

        return traitCollection.verticalSizeClass == .compact ? .overFullScreen : .none
    }

A bit more testing, and it seems like if that function returns the same thing consistently, nothing crashes. Are we not allowed to put conditional logic in this function?

In the crash, we can see that it occurs due to a failing assertion internal to UIPresentationController:

Last Exception Backtrace:
0   CoreFoundation                	0x1afa28cb4 __exceptionPreprocess + 164 (NSException.m:202)
1   libobjc.A.dylib               	0x1a8abc3d0 objc_exception_throw + 60 (objc-exception.mm:356)
2   Foundation                    	0x1aa1b2688 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 172 (NSException.m:251)
3   UIKitCore                     	0x1b1d05610 __80-[UIPresentationController _initViewHierarchyForPresentationSuperview:inWindow:]_block_invoke + 2588 (UIPresentationController.m:1594)
4   UIKitCore                     	0x1b21f1ff4 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_3 + 300 (UIPresentationController.m:1228)

The question

This all leads us to wonder if we're doing something wrong, or if there could be a bug in one of the iOS APIs that we're consuming. Thus, posting here. Does anyone have any insight into how this could be occurring, or has seen this before and has ideas? Thanks!

Miscellaneous info

  • We target iOS 14+
  • We've seen this issue in debug and release builds from Xcode 14 and 15
  • We see the issue on users with iOS 15+, though it could be occurring on 14 in just incredibly low numbers
  • This is a re-post of https://developer.apple.com/forums/thread/738257, because I accidentally closed that out as resolved

Hey @bfreib any updates on that? I've got the same issue but can't figure out the reason

I'm running into the same issue, as well. In my situation I've noticed that the issue (for our circumstances at least) is not reproducible on iPhone 15 Pro running iOS 17+. Our QA was running an iPhone X on 16.?.? (still trying to get that info from them) at the time he found this bug.

Our main Home View can be run in landscape or portrait. We have another View that is used elsewhere in the app. This view is forced into portrait, because it is nearly useless as a landscape View.

In our situation we started showing that secondary view as a sheet over the Home View. When the user is in landscape orientation on the Home View, and taps the button to open this secondary View as a sheet, that is when the crash occurs. Removing the code to force the secondary View into portrait orientation does prevent the bug from occurring (Though not ideally how we'd want to go about things from a UI standpoint).

While I don't think this information will help OP, I figure I'd tack on to this thread in case it ended up helping anyone.

Can you please file a feedback report (https://feedbackassistant.apple.com) with a reproducible testcase that you can attach (even if it only reproduces rarely)? That would help us investigate this issue.

Same issue, marked.

Changing presentation style crashes app
 
 
Q