docs(screen-orientation): fix iOS orientation snippet for UIScene - #2597
Open
aihdene-genetec wants to merge 2 commits into
Open
aihdene-genetec wants to merge 2 commits into
aihdene-genetec wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
supportedInterfaceOrientationsForoverride documented in the iOS section reads the root view controller fromself.window:Capacitor 8.5 adopted the UIScene lifecycle, where the window is created and owned by
SceneDelegate:AppDelegate.windowis therefore alwaysnil, so the force unwrap traps the moment UIKit queries the orientation mask — which happens duringwindow?.makeKeyAndVisible(), before the app ever renders. Following the docs as written on 8.5+ gives a crash on every launch:Changes
windowpassed into the method. UIKit supplies this under both lifecycles, so the snippet works before and after 8.5 without branching on version.as!, returning.allwhen the root view controller isn't aCAPBridgeViewController..allimposes no app-level restriction, so the view controller andInfo.pliststill govern, matching the previous effective behavior when the bridge controller is present.Docs-only; no plugin source is touched. The edit is outside the
<docgen-*>markers, sodocgenwon't overwrite it, and markdown isn't part of the package's prettier glob (**/*.{css,html,ts,js,java}).Testing
Verified on a Capacitor 8.5.2 app (Xcode 27.0, iPad A16 simulator, iOS 27.0): the documented snippet crashes on launch as above, and the updated snippet launches and stays running, with orientation locking still applied to presented view controllers.