I am trying to detect an external display using iOS Swift. The second display is connected with a Lightning Digital AV Adapter. I have imported UIKIt. When I run the code below screens.count just gives me 1 even if I start the app with the second screen already attached and mirroring.
override func viewDidLoad() {
super.viewDidLoad()
// Initialize an external screen if one is present
let screens = UIScreen.screens
print(screens.count)
txtDisplay.text = String(screens.count)
if screens.count > 1 {
print("A second screen has been detected")
//An external screen is available. Get the first screen available
//self.initializeExternalScreen(externalScreen: screens[1] as UIScreen)
}
}
I have loaded demo applications that claim to have this functionality but I just get the same result. Any ideas how I can detect a second display using Swift?
Thanks