Skip to content

Commit

Permalink
fix iOS-app crashing when connecting an external display
Browse files Browse the repository at this point in the history
External display connection invokes
scene:willConnectTo:options again with the
session.role .windowExternalDisplayNonInteractive:
https://developer.apple.com/documentation/uikit/windows_and_screens/presenting_content_on_a_connected_display

This needs to be explicitly handled or rejected,
otherwise the app crashes with the error:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'A view can only be associated with at most one view controller at a time!"
  • Loading branch information
DanielKuhn committed Feb 14, 2024
1 parent 562c969 commit 7b1dbe6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/example/ios/PhoneScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import SwiftUI
class PhoneSceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

if session.role != .windowApplication {
return
}

guard let appDelegate = (UIApplication.shared.delegate as? AppDelegate) else { return }
guard let windowScene = (scene as? UIWindowScene) else { return }

Expand Down
5 changes: 5 additions & 0 deletions apps/stand-alone-example/ios/PhoneScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import SwiftUI
class PhoneSceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

if session.role != .windowApplication {
return
}

guard let appDelegate = (UIApplication.shared.delegate as? AppDelegate) else { return }
guard let windowScene = (scene as? UIWindowScene) else { return }

Expand Down

0 comments on commit 7b1dbe6

Please sign in to comment.