How to resolve: #39;keyWindow#39; was deprecated in iOS 13.0(如何解决:“keyWindow在 iOS 13.0 中已弃用)
问题描述
我将 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 中已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何解决:“keyWindow"在 iOS 13.0 中已弃用
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
