diff --git a/swift-sdk/Internal/IterableUtil.swift b/swift-sdk/Internal/IterableUtil.swift index 7f1eaef42..31da5982a 100644 --- a/swift-sdk/Internal/IterableUtil.swift +++ b/swift-sdk/Internal/IterableUtil.swift @@ -11,7 +11,11 @@ import UIKit if let rootViewController = AppExtensionHelper.application?.delegate?.window??.rootViewController { return rootViewController } else { - return AppExtensionHelper.application?.windows.first?.rootViewController + if #available(iOS 15.0, *) { + return AppExtensionHelper.application?.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.rootViewController + } else { + return AppExtensionHelper.application?.windows.filter {$0.isKeyWindow}.first?.rootViewController + } } }