I have an app that needs to run in portrait mode only on phones. I have the following in AppDelegate:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return UIInterfaceOrientationMask.portrait
}
return UIInterfaceOrientationMask.all
}
The app has a screen with a button that launched the video (with JW Player). The video should launch in fullscreen landscape mode. Upon rotating to portrait, the video player is dismissed.
Up until now, we have been able to manage this in this way (in this example with a local video):
func playLocalVideo(withKey key: String) {
let videoFile = key
let baseUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let assetUrl = baseUrl.appendingPathComponent(videoFile)
var playlist = [JWPlaylistItem]()
let item = JWPlaylistItem()
item.file = assetUrl.absoluteString
playlist.append(item)
let config = JWConfig()
config.playlist = playlist
config.controls = true
config.autostart = true
jwplyr = JWPlayerController(config: config)
jwplyr?.delegate = self
jwplyr?.fullscreen = true
if UIDevice.current.userInterfaceIdiom == .phone {
self.jwplyr?.forceLandscapeOnFullScreen = true
}
}
However, in iOS 16 this doesn't work anymore. When the video launches it goes to fullscreen portrait mode and, even upon device rotation, it never goes to landscape mode.
I have tried overriding supportedInterfaceOrientations but it does nothing:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .all
}
}
I also tried this solution:
var scanModeEnabled = false {
didSet {
if #available(iOS 16.0, *) {
self.setNeedsUpdateOfSupportedInterfaceOrientations()
}
}
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
if scanModeEnabled {
return .all
} else {
return .portrait
}
}
but again nothing happens.
How can I get the landscape mode activated for the player in ios16?