-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(ios): attach temp window to active scene #8316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(ios): attach temp window to active scene #8316
Conversation
Use UIWindowScene for temp presentation windows on iOS 13+ to ensure view controllers like SFSafariViewController are presented from an active scene.
de-dan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the fallback is necessary, since the minimum iOS version is v15 with Capacitor 8.
Capacitor 8’s minimum iOS is 15, but the fallback isn’t about older iOS versions—it’s about scene availability. Even on iOS 15, connectedScenes can be empty or not foregroundActive during app transitions, so creating a UIWindow(windowScene:) can fail. The fallback keeps presentation working in those edge states. It’s a defensive guard with no downside and aligns with Apple’s guidance to present from an active scene when available |
This comment was marked as abuse.
This comment was marked as abuse.
Per review feedback: since Capacitor 8 requires iOS 15+, the #available(iOS 13.0, *) check is unnecessary. Simplified to a single-line assignment while keeping the frame fallback for edge cases where no active scene is available.
|
@de-dan Thanks for the review! You're right, i didn't catch your first part initially. Since Capacitor 8 requires iOS 15+, the I've simplified the code to remove that check. I kept a minimal fallback ( The change is now a single-line assignment: self.tmpWindow = windowScene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds)Let me know if this looks good! |
Summary
UIWindowScenewhen creating the temp presentation window on iOS 13+UIWindow(frame:)when no scene is availableReason for patch:
iOS 13+ requires modal presentation from a UIWindow attached to an active UIWindowScene. Capacitor’s presentVC used UIWindow(frame:), which isn’t scene‑attached, so SFSafariViewController (via @capacitor/browser) could fail to appear. We switched the temp window to use the foreground UIWindowScene when available, with a fallback to UIWindow(frame:) for older iOS or if no scene is active.
Fix
We updated
CapacitorBridge.presentVCto:UIWindowSceneon iOS 13+UIWindow(windowScene:)UIWindow(frame:)when no scene is available (or on iOS < 13)This keeps the presentation path correct for multi‑scene iOS and stabilizes Safari-based flows.
Scope
The change is in
@capacitor/ioscore (not a plugin), but it benefits any plugin that presents view controllers via the bridge, especially@capacitor/browser.