From e4dfe1125a103586f70b3dfc7a3934147c7bf3eb Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 2 Mar 2023 15:00:54 -0600 Subject: [PATCH] Fixes UIApplication.keyWindow deprecation warning --- AltStoreCore/Patreon/PatreonAPI.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/AltStoreCore/Patreon/PatreonAPI.swift b/AltStoreCore/Patreon/PatreonAPI.swift index 0182a457..43d9453b 100644 --- a/AltStoreCore/Patreon/PatreonAPI.swift +++ b/AltStoreCore/Patreon/PatreonAPI.swift @@ -434,6 +434,21 @@ extension PatreonAPI: ASWebAuthenticationPresentationContextProviding { public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { - return UIApplication.alt_shared?.keyWindow ?? UIWindow() + //TODO: Properly support multiple scenes. + + guard let windowScene = UIApplication.alt_shared?.connectedScenes.lazy.compactMap({ $0 as? UIWindowScene }).first else { return UIWindow() } + + if #available(iOS 15, *), let keyWindow = windowScene.keyWindow + { + return keyWindow + } + else if let delegate = windowScene.delegate as? UIWindowSceneDelegate, + let optionalWindow = delegate.window, + let window = optionalWindow + { + return window + } + + return UIWindow() } }