[英]Accessing UIWindow instance in Xcode 11.3 when target is ios 11.0 or letter
The problem is I'm using Xcode 11 which has the new AppDelegate / SceneDelegate setup.问题是我使用的是 Xcode 11,它具有新的 AppDelegate / SceneDelegate 设置。 Because of this, the UIWindow is nil, so the new rootViewController is not set.
因此,UIWindow 为 nil,因此未设置新的 rootViewController。 I know that in iOS 13 the window is accessed in the SceneDelegate, but this project's target is iOS 11 or letter.The SceneDelegate class has been proceeded by @available(iOS 13.0, *).
我知道在 SceneDelegate 中访问 iOS 13 window,但该项目的目标是 iOS 11 或字母。SceneDelegate 类已由@available(iOS 13.0,*)进行。 How can I access UIWindow from the appDelegate?
如何从 appDelegate 访问 UIWindow? I'm working with Xcode 11.3 and Swift 5.0.
我正在使用 Xcode 11.3 和 Swift 5.0。
Here is the extension that i am using in my project这是我在我的项目中使用的扩展
extension UIWindow {
static var key: UIWindow? {
if #available(iOS 13, *) {
return UIApplication.shared.windows.first { $0.isKeyWindow }
} else {
return UIApplication.shared.keyWindow
}
}
}
This is how you use this extension这就是您使用此扩展程序的方式
if let getWindow = UIWindow.key {
// use getWindow to perform action on window
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.