Swift获取keywindow

static var keyWindow: UIWindow? {
        var window: UIWindow?
        if #available(iOS 13.0, *) {
            window = UIApplication.shared.connectedScenes
                .filter({ $0.activationState == .foregroundActive })
                .map({ $0 as? UIWindowScene })
                .compactMap({ $0 })
                .last?.windows
                .filter({ $0.isKeyWindow })
                .last
        } else {
            window = UIApplication.shared.keyWindow
        }
        return window
    }

你可能感兴趣的:(Swift获取keywindow)