if #available(iOS 16, *) {
DispatchQueue.main.async {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
self.setNeedsUpdateOfSupportedInterfaceOrientations()
self.navigationController?.setNeedsUpdateOfSupportedInterfaceOrientations()
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscape)) { error in
print(error)
print(windowScene?.effectiveGeometry ?? "")
}
}
} else {
appDelegate.myOrientation = .landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
UIView.setAnimationsEnabled(true)
}
Apple deprecated UIDevice orientation related api's in iOS_16 instead use requestGeometryUpdate method which requests an update to the window scenes geometry.
For detailed information kindly check the following apple developer documentation.
requestGeometryUpdate
If you still not able to rotate the device successfully, kindly check the below link for possible root cause and the solution.
UISceneErrorDomain Code=101 issue and solution