From 8cc2accf71f88c9d5b17e6d277a3f8f2059ade7a Mon Sep 17 00:00:00 2001 From: simplysparsh Date: Tue, 20 Jan 2026 15:46:33 -0800 Subject: [PATCH 1/2] fix(ios): attach temp window to active scene Use UIWindowScene for temp presentation windows on iOS 13+ to ensure view controllers like SFSafariViewController are presented from an active scene. --- ios/Capacitor/Capacitor/CapacitorBridge.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 8b0026ad9..67cf4ee5d 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -750,7 +750,21 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol { if viewControllerToPresent.modalPresentationStyle == .popover { self.viewController?.present(viewControllerToPresent, animated: flag, completion: completion) } else { - self.tmpWindow = UIWindow.init(frame: UIScreen.main.bounds) + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes + .compactMap { $0 as? UIWindowScene } + .first(where: { $0.activationState == .foregroundActive }) + ?? UIApplication.shared.connectedScenes + .compactMap { $0 as? UIWindowScene } + .first + if let windowScene = windowScene { + self.tmpWindow = UIWindow(windowScene: windowScene) + } else { + self.tmpWindow = UIWindow(frame: UIScreen.main.bounds) + } + } else { + self.tmpWindow = UIWindow(frame: UIScreen.main.bounds) + } self.tmpWindow?.rootViewController = TmpViewController.init() self.tmpWindow?.makeKeyAndVisible() self.tmpWindow?.rootViewController?.present(viewControllerToPresent, animated: flag, completion: completion) From e48db94875ad362a1180dfb3516c009e5e2843fd Mon Sep 17 00:00:00 2001 From: simplysparsh Date: Tue, 20 Jan 2026 17:40:53 -0800 Subject: [PATCH 2/2] refactor: simplify windowScene lookup (remove iOS 13 check) 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. --- ios/Capacitor/Capacitor/CapacitorBridge.swift | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 67cf4ee5d..d2b02d68b 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -750,21 +750,13 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol { if viewControllerToPresent.modalPresentationStyle == .popover { self.viewController?.present(viewControllerToPresent, animated: flag, completion: completion) } else { - if #available(iOS 13.0, *) { - let windowScene = UIApplication.shared.connectedScenes + let windowScene = UIApplication.shared.connectedScenes + .compactMap { $0 as? UIWindowScene } + .first(where: { $0.activationState == .foregroundActive }) + ?? UIApplication.shared.connectedScenes .compactMap { $0 as? UIWindowScene } - .first(where: { $0.activationState == .foregroundActive }) - ?? UIApplication.shared.connectedScenes - .compactMap { $0 as? UIWindowScene } - .first - if let windowScene = windowScene { - self.tmpWindow = UIWindow(windowScene: windowScene) - } else { - self.tmpWindow = UIWindow(frame: UIScreen.main.bounds) - } - } else { - self.tmpWindow = UIWindow(frame: UIScreen.main.bounds) - } + .first + self.tmpWindow = windowScene.map { UIWindow(windowScene: $0) } ?? UIWindow(frame: UIScreen.main.bounds) self.tmpWindow?.rootViewController = TmpViewController.init() self.tmpWindow?.makeKeyAndVisible() self.tmpWindow?.rootViewController?.present(viewControllerToPresent, animated: flag, completion: completion)