UIKit Known Issues Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)
iOS16 how do I force change orientation, any ideas?
UIKit Known Issues Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651)
iOS16 how do I force change orientation, any ideas?
in the Whats new in UIKIt video :
https://developer.apple.com/videos/play/wwdc2022/10068/
they mention UIDevice orientation has gone away. Instead they say use :
Apple released new API which is replaced with setValue:forKey:"orientation". And it's quite easy to use.
iOS apps can now request rotation using [UIWindowScene requestGeometryUpdate:errorHandler:] and providing a UIWindowSceneGeometryPreferencesIOS object containing the desired orientations. (95229615)
https://developer.apple.com/documentation/uikit/uiwindowscene/3975944-requestgeometryupdate/
https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16-release-notes
this works for me
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
But what I cannot get it to do is to honour that rotation change afterwards. I've tried .setNeedsUpdateOfSupportedInterfaceOrientations()
but supportedInterfaceOrientations is ignored.
Force view controller orientation is not working in iOS 16 beta.
I tried preferredInterfaceOrientationForPresentation and requestGeometryUpdate APIs.
In older iOS versions following code snippet given below working fine.
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
Same scenario as you. In iOS beta 3, they mentioned: Attempting to set an orientation on UIDevice via setValue:forKey: isn’t supported and no longer works. (93367651) In iOS beta 4 which is released yesterday, they mentioned it is Fixed.
However, the issue still the same on iOS 16 beta 4
[Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
My code is working fine on older iOS versions too.
This works for me, in iOS 16 beta 3. NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; UIWindowScene *scene = (UIWindowScene *)array[0]; [self setNeedsUpdateOfSupportedInterfaceOrientations]; [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations]; UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskPortrait]; [scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { }];
Calling the attemptRotationToDeviceOrientation()
API on the main thread worked for me (on iOS 16 beta 7).
DispatchQueue.main.async {
UIViewController.attemptRotationToDeviceOrientation()
}
My problem with my code below is that I'm trying to do it when closing a modal view and the view under it are not updated quick enough. If I put the requestGeometryUpdate on a separate button then close the view it work.
if #available(iOS 16.0, *) {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
}
In my ViewController even if I set:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all
}
Still receive error:
Error Domain=UISceneErrorDomain Code=101 "None of the requested orientations are supported by the view controller. Requested: landscapeLeft; Supported: portrait" UserInfo={NSLocalizedDescription=None of the requested orientations are supported by the view controller. Requested: landscapeLeft; Supported: portrait}
When I call:
setNeedsUpdateOfSupportedInterfaceOrientations()
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeLeft)) { error in
print(error)
print(windowScene.effectiveGeometry)
}
when supportedInterfaceOrientations
return .LanscapeLeft
, the orientation of the view is updated, but still receive the same error.
Any help ?
The following code works for me for any orientation
func updateOrientation(orientation: UIInterfaceOrientationMask) { if #available(iOS 16, *) { DispatchQueue.main.async { let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene self.setNeedsUpdateOfSupportedInterfaceOrientations() self.navigationController?.setNeedsUpdateOfSupportedInterfaceOrientations() windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation)) { error in print(error) print(windowScene?.effectiveGeometry ?? "") } } }
}
I found that no matter how I use requestGeometryUpdate it doesn't work on ipad os beta 16
I am also seeing a very strange issue with orientation. I am changing the orientation with requestGeometryUpdate. Sometimes it changes it correctly and sometimes it did not change the orientation. I am trying to change the orientation to portrait and in the error message it says "None of the requested orientations are supported by the view controller" but it supports "portrait, landscapeLeft, landscapeRight".
Error Message:
sample[1233:173290] Error Occured while changing orientation of app : Error Domain=UISceneErrorDomain Code=101 "None of the requested orientations are supported by the view controller. Requested: portrait; Supported: portrait, landscapeLeft, landscapeRight" UserInfo={NSLocalizedDescription=None of the requested orientations are supported by the view controller. Requested: portrait; Supported: portrait, landscapeLeft, landscapeRight}
I'm having the same problem. I have a custom player in a UIVIew and on full screen it doesn't rotate. I have this massage: Error Domain=UISceneErrorDomain Code=101 "None of the requested orientations are supported by the view controller. Requested: landscapeLeft, landscapeRight; Supported: portrait" UserInfo={NSLocalizedDescription=None of the requested orientations are supported by the view controller. Requested: landscapeLeft, landscapeRight; Supported: portrait} Anyone found a solution?