diff --git a/screen-orientation/README.md b/screen-orientation/README.md index f8a3791e4..7e57cb872 100644 --- a/screen-orientation/README.md +++ b/screen-orientation/README.md @@ -16,10 +16,25 @@ For also lock presented View Controllers, this code can be added to the app's `A ```swift func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { - return UIInterfaceOrientationMask(rawValue: (self.window!.rootViewController as! CAPBridgeViewController).supportedInterfaceOrientations.rawValue) + guard let bridgeViewController = window?.rootViewController as? CAPBridgeViewController else { + return .all + } + return bridgeViewController.supportedInterfaceOrientations } ``` +> **Warning** +> +> If your app already has an earlier version of this snippet, update it. Capacitor 8.5 and later adopt the UIScene lifecycle, in which the window is owned by `SceneDelegate`, so `self.window` on the `AppDelegate` is always `nil` and the previous snippet crashes on launch. Read the root view controller from the `window` passed into the method instead: +> +> ```diff +> - return UIInterfaceOrientationMask(rawValue: (self.window!.rootViewController as! CAPBridgeViewController).supportedInterfaceOrientations.rawValue) +> + guard let bridgeViewController = window?.rootViewController as? CAPBridgeViewController else { +> + return .all +> + } +> + return bridgeViewController.supportedInterfaceOrientations +> ``` + ### iPad Orientation Lock By default, an iPad allows Multitasking and its orientation cannot be locked. If you need to lock orientation on an iPad set the option `Requires Full Screen` to `YES` by adding the following to `Info.plist`: