UIKit Known Issues Attempting to set an orientation on UIDevice via setValue:forKey:
I am able to rotate the orientation programmatically but the notification is not getting triggered until the device orientation is changed physically, any ideas?
I tried these but didn't work in ios16, same code works in the older version
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
DispatchQueue.main.async {
UIViewController.attemptRotationToDeviceOrientation()
}
on viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(playerVC.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
Environment:
Xcode 14
Swift 5
Simulator iPhone 14 ios16