What is the current best-practice for supporting an external display in a SwiftUI iOS app in 2024? Not simple mirroring, but actually displaying different content than the device.
The only docs I found require abandoning the SwiftUI App structure and “switching back to a full UIKit App Delegate”.
Is this still the only option?
Are there any complete examples on how to accomplish this?
Even the examples I found I cannot get working b/c the registered delegate never gets called.
Info.plist
is configured as:
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleExternalDisplayNonInteractive</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>External Display</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).ExternalDisplaySceneDelegate</string>
</dict>
</array>
</dict>
</dict>
And here is the delegate class:
final class ExternalDisplaySceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
print("external scene") // ⬅︎----- I can never get this to print
guard let scene = scene as? UIWindowScene else {
return
}
let content = ExternalDisplayView()
window = UIWindow(windowScene: scene)
window?.rootViewController = UIHostingController(rootView: content)
window?.isHidden = false
}
}
Am I doing something wrong?
Is there a better way?
(Note: I’m only interested in iOS 17 and/or iOS 18)
Thanks in advance.