问题描述
我将 Core Data 与 Cloud Kit 一起使用,因此必须在应用程序启动期间检查 iCloud 用户状态.如果出现问题,我想向用户发出一个对话框,并且我使用 UIApplication.shared.keyWindow?.rootViewController?.present(...)
到现在为止.
I'm using Core Data with Cloud Kit, and have therefore to check the iCloud user status during application startup. In case of problems I want to issue a dialog to the user, and I do it using UIApplication.shared.keyWindow?.rootViewController?.present(...)
up to now.
在 Xcode 11 beta 4 中,现在有一条新的弃用消息,告诉我:
In Xcode 11 beta 4, there is now a new deprecation message, telling me:
'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
我应该如何呈现对话框?
How shall I present the dialog instead?
推荐答案
这是我的解决方案:
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.compactMap({$0 as? UIWindowScene})
.first?.windows
.filter({$0.isKeyWindow}).first
用法例如:
keyWindow?.endEditing(true)
这篇关于如何解决:“keyWindow"在 iOS 13.0 中已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!