Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyWindow fix #737

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions OpenHABCore/Sources/OpenHABCore/Util/NetworkConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?
Expand Down
6 changes: 5 additions & 1 deletion openHAB/OpenHABRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions openHAB/OpenHABSitemapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,15 @@ 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)
}

// sessionDelegate.onReceiveSessionChallenge
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)
}
}
4 changes: 2 additions & 2 deletions openHAB/OpenHABWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion openHAB/WebUITableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions openHABWatch Extension/ExtensionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ 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)
}

// sessionDelegate.onReceiveSessionChallenge
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)
}
}
Expand Down