Skip to content

Commit 851e798

Browse files
committed
Stop using deprecated keyWindow API
1 parent 74de8be commit 851e798

5 files changed

+31
-3
lines changed

SwiftMessages.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2041EE47DC900E2DDC1 /* Weak.swift */; };
5555
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2061EE480D000E2DDC1 /* Animator.swift */; };
5656
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */; };
57+
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */; };
5758
22DFC9161EFF30F6001B1CA1 /* CenteredView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */; };
5859
22DFC9181F00674E001B1CA1 /* PhysicsPanHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */; };
5960
22E01F641E74EC8B00ACE19A /* MaskingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22E01F631E74EC8B00ACE19A /* MaskingView.swift */; };
@@ -140,6 +141,7 @@
140141
2298C2041EE47DC900E2DDC1 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
141142
2298C2061EE480D000E2DDC1 /* Animator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = "<group>"; };
142143
2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopBottomAnimation.swift; sourceTree = "<group>"; };
144+
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+Extensions.swift"; sourceTree = "<group>"; };
143145
22A2EA6E24EC6CFA00BB2540 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
144146
22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CenteredView.xib; path = Resources/CenteredView.xib; sourceTree = "<group>"; };
145147
22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhysicsPanHandler.swift; sourceTree = "<group>"; };
@@ -209,6 +211,7 @@
209211
children = (
210212
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */,
211213
22774B9F20B5EF2A00813732 /* UIEdgeInsets+Extensions.swift */,
214+
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
212215
);
213216
name = Extensions;
214217
sourceTree = "<group>";
@@ -546,6 +549,7 @@
546549
86BBA9041D5E040600FE8F16 /* NSBundle+Extensions.swift in Sources */,
547550
86BBA8FD1D5E03F800FE8F16 /* SwiftMessages.swift in Sources */,
548551
86BBA9021D5E040600FE8F16 /* WindowViewController.swift in Sources */,
552+
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */,
549553
86BBA8FF1D5E040600FE8F16 /* Presenter.swift in Sources */,
550554
86BBA9051D5E040C00FE8F16 /* Theme.swift in Sources */,
551555
86BBA9081D5E040C00FE8F16 /* Error.swift in Sources */,

SwiftMessages/Presenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class Presenter: NSObject {
301301
#if SWIFTMESSAGES_APP_EXTENSIONS
302302
throw SwiftMessagesError.noRootViewController
303303
#else
304-
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
304+
if let rootViewController = UIWindow.keyWindow?.rootViewController {
305305
let viewController = rootViewController.sm_selectPresentationContextTopDown(config)
306306
return .viewController(Weak(value: viewController))
307307
} else {

SwiftMessages/SwiftMessages.Config+Extensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension SwiftMessages.Config {
2525
#if SWIFTMESSAGES_APP_EXTENSIONS
2626
return nil
2727
#else
28-
return UIApplication.shared.keyWindow?.windowScene
28+
return UIWindow.keyWindow?.windowScene
2929
#endif
3030
}
3131
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// UIWindow+Extensions.swift
3+
// SwiftMessages
4+
//
5+
// Created by Timothy Moose on 3/11/21.
6+
// Copyright © 2021 SwiftKick Mobile. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIWindow {
12+
static var keyWindow: UIWindow? {
13+
if #available(iOS 13.0, *) {
14+
return UIApplication.shared.connectedScenes
15+
.filter { $0.activationState == .foregroundActive }
16+
.compactMap { $0 as? UIWindowScene }
17+
.first?.windows
18+
.filter { $0.isKeyWindow }
19+
.first
20+
} else {
21+
return UIApplication.shared.keyWindow
22+
}
23+
}
24+
}

SwiftMessages/WindowViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open class WindowViewController: UIViewController
3737
window?.windowScene = config.windowScene
3838
if config.shouldBecomeKeyWindow {
3939
#if !SWIFTMESSAGES_APP_EXTENSIONS
40-
previousKeyWindow = UIApplication.shared.keyWindow
40+
previousKeyWindow = UIWindow.keyWindow
4141
#endif
4242
}
4343
show(

0 commit comments

Comments
 (0)