I am trying to set up a SwiftUI app that shows different UI on the device's app and the external, non-interactive display (like Keynote does when presenting).
What I have so far:
@mainapp structure with@UIApplicationDelegateAdaptor(AppDelegate.self)InternalDisplayViewandExternalDisplayView. If possible I would like the latter to only show up on an external display (and not for example in another window on an iPad).- I have noticed that observing
UIScreen.didConnectNotificationworks, but it's deprecated and I suppose will be removed since Xcode 16, hence I want to useUIAppDelegateandUIWindowSceneDelegate.
I have tried both setting up the info.plist with two different scene types and setting up none, set Enable Multiple Windows to both YES and NO.
In AppDelegate I have:
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let config: UISceneConfiguration = if connectingSceneSession.configuration.role == .windowExternalDisplayNonInteractive {
.init(name: "External",
sessionRole: .windowExternalDisplayNonInteractive)
} else {
.init(name: "Default",
sessionRole: connectingSceneSession.role)
}
config.delegateClass = SceneDelegate.self // my custom SceneDelegate
return config
}
But when connecting an external display the .windowExternalDisplayNonInteractive role is not set. In fact, this AppDelegate function does not get called when display connects at all.
What am I doing incorrectly in this setup?