如何解决:iOS 13.0 中不推荐使用“keyWindow" [英] How to resolve: 'keyWindow' was deprecated in iOS 13.0

查看:37
本文介绍了如何解决:iOS 13.0 中不推荐使用“keyWindow"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 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)

这篇关于如何解决:iOS 13.0 中不推荐使用“keyWindow"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆