Xcode 11向后兼容:"UIWindowScene仅在iOS 13或更高版本中可用". [英] Xcode 11 backward compatibility: "UIWindowScene is only available in iOS 13 or newer"

查看:1961
本文介绍了Xcode 11向后兼容:"UIWindowScene仅在iOS 13或更高版本中可用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode 11中,我从Single View App模板创建了一个新的应用程序项目.我希望该应用程序可以在iOS 12和iOS 13中运行.但是,当我将部署目标切换到iOS 12时,我收到了很多类似以下的错误消息:

In Xcode 11, I created a new app project from the Single View App template. I want this app to run in iOS 12 as well as iOS 13. But when I switch the deployment target to iOS 12, I got a lot of error messages like this one:

UIWindowScene仅在iOS 13或更高版本中可用

UIWindowScene is only available in iOS 13 or newer

我该怎么办?

推荐答案

Xcode 11中的模板使用场景委托.场景委托和相关类是iOS 13中的新增功能;它们在iOS 12及更高版本中不存在,并且启动过程有所不同.

The template in Xcode 11 uses a scene delegate. Scene delegates and the related classes are new in iOS 13; they don't exist in iOS 12 and before, and the launch process is different.

要使从Xcode 11应用程序模板生成的项目向后兼容,您需要将整个SceneDelegate类以及AppDelegate类中所有引用UISceneSession的方法标记为@available(iOS 13.0, *).

To make a project generated from an Xcode 11 app template backward compatible, you need to mark the entire SceneDelegate class, and any methods in the AppDelegate class that refer to UISceneSession, as @available(iOS 13.0, *).

您还需要在AppDelegate类中声明一个window属性(如果不这样做,则该应用将运行并启动,但屏幕将变为黑色):

You also need to declare a window property in the AppDelegate class (if you don't do that, the app will run and launch but the screen will be black):

var window : UIWindow?

结果是,当此应用程序在iOS 13中运行时,场景委托具有window,但是在iOS 12或更低版本中运行时,该应用程序委托具有window-然后您可能需要其他代码考虑到那个以便向后兼容.

The result is that when this app runs in iOS 13, the scene delegate has the window, but when it runs in iOS 12 or before, the app delegate has the window — and your other code may then need to take account of that in order to be backward compatible.

这篇关于Xcode 11向后兼容:"UIWindowScene仅在iOS 13或更高版本中可用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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