当前位置:   article > 正文

Swift获取window包含iOS15后的改动附带OC写法_windows' was deprecated in ios 15.0: use uiwindows

windows' was deprecated in ios 15.0: use uiwindowscene.windows on a relevan
在这里插入代码片
  • 1

问题报错:‘windows’ was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead

let keyWindow:UIWindow = {
if #available(iOS 13.0, *) {
return UIApplication.shared.windows.filter({ $0.isKeyWindow }).last!
}else {
return UIApplication.shared.keyWindow!
}
}()

更改为

let keyWindow : UIWindow? = {
if #available(iOS 13.0, *) {
return UIApplication.shared.connectedScenes.filter { $0.activationState == .foregroundActive }
.compactMap { $0 as? UIWindowScene }.first?.windows
.filter { $0.isKeyWindow }.first;
}else {
return UIApplication.shared.keyWindow!
}
}()

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号