发布于 4年前

iOS 13.0废弃'keyWindow'的解决方法

使用In Xcode 11 beta 4,提示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

解决方法

方法一:

UIApplication.shared.windows.filter {$0.isKeyWindow}.first

或者:

UIApplication.shared.windows.first { $0.isKeyWindow }

方法二:

let keyWindow = UIApplication.shared.connectedScenes
        .filter({$0.activationState == .foregroundActive})
        .map({$0 as? UIWindowScene})
        .compactMap({$0})
        .first?.windows
        .filter({$0.isKeyWindow}).first

使用:

keyWindow?.endEditing(true)
©2020 edoou.com   京ICP备16001874号-3