iOS16 change orientaion

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?

Post not yet marked as solved Up vote post of sgxdev Down vote post of sgxdev
16k views

Replies

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 :

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621438-preferredinterfaceorientationfor

  • i tried to call the method 'attemptRotationToDeviceOrientation' on ios16, and the delegate method 'preferredInterfaceOrientationForPresentation' was called it returned the right value, but nothing happend

Add a Comment

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

  • It does not work for me

Add a Comment

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.

  • Were you ever able to get the orientation to lock after using requestGeometryUpdate?

Add a Comment

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")
Add a Comment

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.

  • Getting same error on orientation

    `[Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)

    Any fix for this issue?

Add a Comment

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) { }];

  • Hi @dina2ms I'm from RN background and new to obj-c. I've the same situation at my end where the landscape mode is not working for ios16. I'm try yours and i get the compiler error throwing "No known class method for selector 'setNeedsUpdateOfSupportedInterfaceOrientations' " and the for this line [self->navigationController setNeedsUpdateOfSupportedInterfaceOrientations], it throws "Member reference basetype class is not a structure or union"

    Your help is highly appreciated.

  • Hi, I'm looking for obj-c solution and i tried the above and it shows compiler error as "No known class method for selector 'setNeedsUpdateOfSupportedInterfaceOrientations' ". And this line [self->navigationController setNeedsUpdateOfSupportedInterfaceOrientations]; shows Member reference base type is not a structure or union. Please advise

Add a Comment

Calling the attemptRotationToDeviceOrientation() API on the main thread worked for me (on iOS 16 beta 7).

DispatchQueue.main.async {
     UIViewController.attemptRotationToDeviceOrientation()
}
  • It does not work for me

  • same here not working for me

Add a Comment

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))

        } 
  • Hi @braillant, I'm from react native background and new to obj-c and swift here. We have our implementation in obj-c which doesn't work as it uses setValue. Could you please let me know how to apply your above solution in obj-c.

    Regards, BT

Add a Comment

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 ?

  • Hi, I have the same issue on iOS 16. Did you find a fix ? Thanks

  • same problem.

  • Hey, the issue on my side was that I call the requestGeometryUpdate in viewWillAppear, at this moments the supported interface orientation always return portrait even if the (presenting / presented) ViewControllers support landscape. 2 options:

    Delay the first call after viewDidAppear / viewWillAppear.Rotate before presenting the new VC.

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 have the same issue. Except that this is working for me... in that I can use this new API to lock the orientation of the UI (as well as unlock it). However, it always ignores the UIInterfaceOrientationMask I give it and just does portrait. iPadOS 16 only.

Add a Comment

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}
  • Same problem. Are there solutions to this problem?

  • Hi, Do you have any solution for your issue above as i'm also facing the same.

Add a Comment

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?

  • Hi, Do you have any updates for the above problem as i'm also facing the same.

  • No, unfortunately not.

Add a Comment