From 15c660bce76735d2736c944989e9c72095a1e218 Mon Sep 17 00:00:00 2001
From: Harry <harry@wombatinvest.com>
Date: Mon, 20 Nov 2023 14:05:05 +0000
Subject: [PATCH 1/3] Implement keyWindow fix

---
 swift-sdk/Internal/IterableUtil.swift | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swift-sdk/Internal/IterableUtil.swift b/swift-sdk/Internal/IterableUtil.swift
index 80dbd4b8d..b7f1c703b 100644
--- a/swift-sdk/Internal/IterableUtil.swift
+++ b/swift-sdk/Internal/IterableUtil.swift
@@ -11,7 +11,7 @@ import UIKit
         if let rootViewController = AppExtensionHelper.application?.delegate?.window??.rootViewController {
             return rootViewController
         } else {
-            return AppExtensionHelper.application?.windows.first?.rootViewController
+            return AppExtensionHelper.application?.windows.filter {$0.isKeyWindow}.first?.rootViewController
         }
     }
     

From 523cb3e342d34e3f22d067d320551628ee02242d Mon Sep 17 00:00:00 2001
From: Harry <harry@wombatinvest.com>
Date: Mon, 20 Nov 2023 14:18:57 +0000
Subject: [PATCH 2/3] Handle deprecations

---
 swift-sdk/Internal/IterableUtil.swift | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/swift-sdk/Internal/IterableUtil.swift b/swift-sdk/Internal/IterableUtil.swift
index b7f1c703b..9a5909208 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.filter {$0.isKeyWindow}.first?.rootViewController
+            if #available(iOS 15.0, *) {
+                return AppExtensionHelper.application?.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.rootViewController
+            } else {
+                return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
+            }
         }
     }
     

From c414fa8a8d8800d204180b6c945a1cd53caf1438 Mon Sep 17 00:00:00 2001
From: Harry <harry@wombatinvest.com>
Date: Mon, 20 Nov 2023 14:19:33 +0000
Subject: [PATCH 3/3] Handle deprecations

---
 swift-sdk/Internal/IterableUtil.swift | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swift-sdk/Internal/IterableUtil.swift b/swift-sdk/Internal/IterableUtil.swift
index 9a5909208..3cd0f4858 100644
--- a/swift-sdk/Internal/IterableUtil.swift
+++ b/swift-sdk/Internal/IterableUtil.swift
@@ -14,7 +14,7 @@ import UIKit
             if #available(iOS 15.0, *) {
                 return AppExtensionHelper.application?.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.rootViewController
             } else {
-                return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
+                return AppExtensionHelper.application?.windows.filter {$0.isKeyWindow}.first?.rootViewController
             }
         }
     }