From cf6b3f2032bbec48186bbe68161a669d3e10ffd5 Mon Sep 17 00:00:00 2001 From: Abdelmalek Ihdene Date: Wed, 16 Sep 2026 14:47:01 -0400 Subject: [PATCH 1/2] docs(screen-orientation): fix iOS orientation snippet for UIScene The documented `supportedInterfaceOrientationsFor` override reads the root view controller from `self.window`. Capacitor 8.5 adopted the UIScene lifecycle, where the window is created and owned by `SceneDelegate`, so `self.window` on the `AppDelegate` is always nil and the force unwrap traps on launch. Read the root view controller from the `window` passed into the method, which UIKit supplies under both lifecycles, and use a conditional cast so a non-bridge root view controller returns `.all` rather than crashing. Also add a note with a before/after diff for apps that already copied the previous snippet. --- screen-orientation/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/screen-orientation/README.md b/screen-orientation/README.md index f8a3791e46..e00a7ca47e 100644 --- a/screen-orientation/README.md +++ b/screen-orientation/README.md @@ -16,10 +16,24 @@ 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 } ``` +> [!IMPORTANT] +> 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`: From 865c92547107bfab27fd3727b4019b8552b4b944 Mon Sep 17 00:00:00 2001 From: Malek <139482451+aihdene-genetec@users.noreply.github.com> Date: Wed, 23 Sep 2026 13:26:38 -0400 Subject: [PATCH 2/2] Update screen-orientation/README.md Co-authored-by: OS-ruimoreiramendes --- screen-orientation/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/screen-orientation/README.md b/screen-orientation/README.md index e00a7ca47e..7e57cb872f 100644 --- a/screen-orientation/README.md +++ b/screen-orientation/README.md @@ -23,7 +23,8 @@ func application(_ application: UIApplication, supportedInterfaceOrientationsFor } ``` -> [!IMPORTANT] +> **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