diff --git a/OpenHABCore/Sources/OpenHABCore/Util/NetworkConnection.swift b/OpenHABCore/Sources/OpenHABCore/Util/NetworkConnection.swift index 573b8f6f3..fc6784916 100644 --- a/OpenHABCore/Sources/OpenHABCore/Util/NetworkConnection.swift +++ b/OpenHABCore/Sources/OpenHABCore/Util/NetworkConnection.swift @@ -13,9 +13,7 @@ import Alamofire import Foundation import os.log -// https://medium.com/@AladinWay/write-a-networking-layer-in-swift-4-using-alamofire-5-and-codable-part-2-perform-request-and-b5c7ee2e012d - -public let onReceiveSessionTaskChallenge = { (_: URLSession, _: URLSessionTask, challenge: URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?) in +public func onReceiveSessionTaskChallenge(with challenge: URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?) { os_log("onReceiveSessionTaskChallenge host:'%{PUBLIC}@'", log: .default, type: .error, challenge.protectionSpace.host) var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling var credential: URLCredential? @@ -34,7 +32,7 @@ public let onReceiveSessionTaskChallenge = { (_: URLSession, _: URLSessionTask, return (disposition, credential) } -public let onReceiveSessionChallenge = { (_: URLSession, challenge: URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?) in +public func onReceiveSessionChallenge(with challenge: URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?) { os_log("onReceiveSessionChallenge host:'%{PUBLIC}@'", log: .default, type: .error, challenge.protectionSpace.host) var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling var credential: URLCredential? diff --git a/openHAB/OpenHABRootViewController.swift b/openHAB/OpenHABRootViewController.swift index 9d1f95f0c..097a8e9bf 100644 --- a/openHAB/OpenHABRootViewController.swift +++ b/openHAB/OpenHABRootViewController.swift @@ -179,7 +179,11 @@ class OpenHABRootViewController: UIViewController { if let menu = SideMenuManager.default.rightMenuNavigationController { // don't try and push an already visible menu less you crash the app dismiss(animated: false) { - var topMostViewController = UIApplication.shared.keyWindow?.rootViewController + var topMostViewController: UIViewController? = if #available(iOS 13, *) { + UIApplication.shared.connectedScenes.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }.last { $0.isKeyWindow }?.rootViewController + } else { + UIApplication.shared.keyWindow?.rootViewController + } while let presentedViewController = topMostViewController?.presentedViewController { topMostViewController = presentedViewController } diff --git a/openHAB/OpenHABSitemapViewController.swift b/openHAB/OpenHABSitemapViewController.swift index be0b41128..d825bb955 100644 --- a/openHAB/OpenHABSitemapViewController.swift +++ b/openHAB/OpenHABSitemapViewController.swift @@ -811,7 +811,7 @@ extension OpenHABSitemapViewController: AuthenticationChallengeResponsible { task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let (disposition, credential) = onReceiveSessionTaskChallenge(URLSession(configuration: .default), task, challenge) + let (disposition, credential) = onReceiveSessionTaskChallenge(with: challenge) completionHandler(disposition, credential) } @@ -819,7 +819,7 @@ extension OpenHABSitemapViewController: AuthenticationChallengeResponsible { func downloader(_ downloader: ImageDownloader, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let (disposition, credential) = onReceiveSessionChallenge(URLSession(configuration: .default), challenge) + let (disposition, credential) = onReceiveSessionChallenge(with: challenge) completionHandler(disposition, credential) } } diff --git a/openHAB/OpenHABWebViewController.swift b/openHAB/OpenHABWebViewController.swift index 721108404..cc2083843 100644 --- a/openHAB/OpenHABWebViewController.swift +++ b/openHAB/OpenHABWebViewController.swift @@ -297,9 +297,9 @@ extension OpenHABWebViewController: WKNavigationDelegate { var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling var credential: URLCredential? if challenge.protectionSpace.authenticationMethod.isAny(of: NSURLAuthenticationMethodHTTPBasic, NSURLAuthenticationMethodDefault) { - (disposition, credential) = onReceiveSessionTaskChallenge(URLSession(configuration: .default), URLSessionDataTask(), challenge) + (disposition, credential) = onReceiveSessionTaskChallenge(with: challenge) } else { - (disposition, credential) = onReceiveSessionChallenge(URLSession(configuration: .default), challenge) + (disposition, credential) = onReceiveSessionChallenge(with: challenge) } completionHandler(disposition, credential) } diff --git a/openHAB/WebUITableViewCell.swift b/openHAB/WebUITableViewCell.swift index a88a810f3..acee8b323 100644 --- a/openHAB/WebUITableViewCell.swift +++ b/openHAB/WebUITableViewCell.swift @@ -105,7 +105,7 @@ extension WebUITableViewCell: WKNavigationDelegate { } func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let (disposition, credential) = onReceiveSessionChallenge(URLSession(configuration: .default), challenge) + let (disposition, credential) = onReceiveSessionChallenge(with: challenge) completionHandler(disposition, credential) } } diff --git a/openHABWatch Extension/ExtensionDelegate.swift b/openHABWatch Extension/ExtensionDelegate.swift index ede5e53c6..9e352fb11 100644 --- a/openHABWatch Extension/ExtensionDelegate.swift +++ b/openHABWatch Extension/ExtensionDelegate.swift @@ -106,7 +106,7 @@ extension ExtensionDelegate: AuthenticationChallengeResponsible { task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let (disposition, credential) = onReceiveSessionTaskChallenge(URLSession(configuration: .default), task, challenge) + let (disposition, credential) = onReceiveSessionTaskChallenge(with: challenge) completionHandler(disposition, credential) } @@ -114,7 +114,7 @@ extension ExtensionDelegate: AuthenticationChallengeResponsible { func downloader(_ downloader: ImageDownloader, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let (disposition, credential) = onReceiveSessionChallenge(URLSession(configuration: .default), challenge) + let (disposition, credential) = onReceiveSessionChallenge(with: challenge) completionHandler(disposition, credential) } }