diff --git a/ios/extensions/UIApplication.swift b/ios/extensions/UIApplication.swift index 41e1fa4bb8..19a1ed0863 100644 --- a/ios/extensions/UIApplication.swift +++ b/ios/extensions/UIApplication.swift @@ -9,6 +9,22 @@ import Foundation import UIKit public extension UIApplication { + var activeWindow: UIWindow? { + if #available(iOS 13.0, *) { + for scene in connectedScenes { + if scene.activationState == .foregroundActive, + let windowScene = scene as? UIWindowScene, + let keyWindow = windowScene.windows.first(where: { $0.isKeyWindow }) + { + return keyWindow + } + } + return nil + } else { + return windows.last { $0.isKeyWindow } + } + } + static func topViewController( base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController ) -> UIViewController? { diff --git a/ios/extensions/UIWindow.swift b/ios/extensions/UIWindow.swift index ead6e37fd6..c73fc1be4a 100644 --- a/ios/extensions/UIWindow.swift +++ b/ios/extensions/UIWindow.swift @@ -38,7 +38,7 @@ public extension UIWindow { func getTopWindow() -> UIWindow? { // Return the keyboard window if it's available, otherwise return the last window - return keyboardWindow ?? UIApplication.shared.windows.last + return keyboardWindow ?? UIApplication.shared.activeWindow } }