iOS 16 Scene orientation issue

Viewed 1000

I always received this error when I tried to allowed only portrait orientation on my controller: 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}

I called this method:
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 )
                }
            }
        }
    }

Did someone face the same issue ?
2 Answers

Yes, I faced the same issue and resolved it as below. Provided error clearly saying that we are trying to rotate the device where we are restricting it to use only in one mode previously somewhere in the app. In my case I was implemented below method in Appdelegate.swift

var myOrientation: UIInterfaceOrientationMask = .portrait

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return myOrientation }

so restricting it to only use the portrait mode, caused to fail the rotation of the app in landscape mode.

By changing the orientation to all, makes it work.

var myOrientation: UIInterfaceOrientationMask = .portrait

try it in Appdelegate

  • (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; }
Related