(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window is broken in iOS 16

I’m trying to lock the orientation on iOS 16, to either landscape or portrait, at different times in my app.

So change the orientation on iOS 16 by using new method requestGeometryUpdateWithPreferences works fine, it changes the orientation correctly.

But supportedInterfaceOrientationsForWindow seems broken the flow in iOS 16. It does not lock the orientation there. It should ask allowed orientation before changing the orienation but now it does not work as expected nor according the decumentation. It changes the orienation and then asks supportedInterfaceOrientationsForWindow, that is wrong according to documentation. It was working fine on less than iOS 16.

I am using XCode Version 14.0 and iOS 16.0

Replies

same issue

Yes same issue I am also facing. I does not lock the orientation, when I was trying to rotate it is rotating

I am just try to add 2 button in screen for portrait and landscape. when we clicks portrait it should be portrait mode same when we click landscape it should be landscape. its working fine in that case. but when I rotate the device screen is display in both the mode , As per my logic it should be lock.

Swift Helper Class I am using in objective c code @objc public class HelperSwift: UIViewController {

       @objc static func setDeviceOrientation(orientation: UIInterfaceOrientationMask , controller:UIViewController) {

           if #available(iOS 16.0, *) {

            let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene

            windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation)) { error in

                print("orientation error", error.localizedDescription)

            }

        } else {

            UIDevice.current.setValue(orientation.toUIInterfaceOrientation.rawValue, forKey: "orientation")

        }

    }

}

extension UIInterfaceOrientationMask {

    var toUIInterfaceOrientation: UIInterfaceOrientation {

        switch self {

        case .portrait:

            return UIInterfaceOrientation.portrait

        case .portraitUpsideDown:

            return UIInterfaceOrientation.portraitUpsideDown

        case .landscapeRight:

            return UIInterfaceOrientation.landscapeRight

        case .landscapeLeft:

            return UIInterfaceOrientation.landscapeLeft

        default:

            return UIInterfaceOrientation.unknown

        }

    }

}

ViewController @implementation ViewController

  • (void)viewDidLoad {

    [super viewDidLoad];

}

-(IBAction)landScape:(id)sender {

    orientation = UIInterfaceOrientationMaskLandscapeLeft;

    [HelperSwift setDeviceOrientationWithOrientation:orientation controller:self];

}

-(IBAction)portrait:(id)sender {     orientation = UIInterfaceOrientationMaskPortrait;     [HelperSwift setDeviceOrientationWithOrientation:orientation controller:self]; }

  • (void)setNeedsUpdateOfSupportedInterfaceOrientations {

    NSLog(@"Called rotate the device and orientation is change"); } // this is deprecated -(BOOL)shouldAutorotate {     UIDeviceOrientation orientationA = [[UIDevice currentDevice] orientation];     return YES;

}

  • (UIInterfaceOrientationMask)supportedInterfaceOrientations

{     NSUInteger supportedOrientations = orientation;     return supportedOrientations; }