UIHostingController crash when added as child controller on iOS 15

Hello,

We are trying to move the UIKit component which is a SwiftUI component. Since our HomeScreenViewController is subclass of UIViewController we have used UIHostingController to embed this SwiftUI view by adding the hosting view controller’s sub view to HomeScreenViewController’s view’s subview which is UIStackView and also by adding the UIHostingController as the child controller of HomeScreenViewController. This works fine on iOS 16+. But it is causing the following issues on iOS 15.

Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x2807ac740 "UIStackView:0x122b0caf0.bottom"> and <NSLayoutYAxisAnchor:0x2804ff600 "TtGC7SwiftUI14_UIHostingViewV7Loyalty15LargeBannerView:0x135930690.bottom"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.

It crashes with the above exception inside [UIHostingController viewWillAppear] where it is trying to set some constraints in side navigationBarHidden method. Also it is messing up the navigation bar hidden status. Could you please help us with this? But this issue will not come if we don’t add UIHostingController as child of our home screen controller and only add UIHostingController’s view as subview. Please find the attached screenshot for the stack trace.

Could you please help us with this.

Thanks

Could you submitted a bug report and include the complete Apple crash report with its original formatting preserved.

Post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating your bug report.

Hello @DTS Engineer , Could you please let me know if there is any update from the engineering team regarding this issue.

UIHostingController crash when added as child controller on iOS 15
 
 
Q