let window = UIApplication.shared.keyWindow
提示keyWindow已经被iOS 13.0废弃
'keyWindow' was deprecated in iOS 13.0: Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes
解决办法:
let window = UIApplication.shared.windows
//.filter({ $0.isKeyWindow })
.last
var window: UIWindow? = nil
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
}