Use modern APIs for accessing key window

Shouldn't be relying on deprecated API. Tsk. Tsk.
This commit is contained in:
Chase Carroll 2022-12-05 16:01:41 -05:00
parent 7f58422900
commit 4689c8e78f
2 changed files with 10 additions and 2 deletions

View File

@ -22,5 +22,13 @@ extension UIApplication {
return version == build ? "v\(version)" : "v\(version) (\(build))"
}
func getKeyWindow() -> UIWindow? {
return UIApplication
.shared
.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.first { $0.isKeyWindow }
}
}

View File

@ -122,8 +122,8 @@ extension HomeTimelineViewController {
identifier: nil,
options: [],
children: [
UIAction(title: "Toggle Visible Touches", image: UIImage(systemName: "hand.tap"), attributes: []) { [weak self] action in
guard let window = UIApplication.shared.keyWindow as? TouchesVisibleWindow else { return }
UIAction(title: "Toggle Visible Touches", image: UIImage(systemName: "hand.tap"), attributes: []) { _ in
guard let window = UIApplication.shared.getKeyWindow() as? TouchesVisibleWindow else { return }
window.touchesVisible = !window.touchesVisible
},
UIAction(title: "Toggle EmptyView", image: UIImage(systemName: "clear"), attributes: []) { [weak self] action in