mat*_*att 22 xcode ios xcode11
在Xcode 11中,我从Single View App模板创建了一个新的应用程序项目。我希望此应用程序可以在iOS 12和iOS 13中运行。但是,当我将部署目标切换到iOS 12时,出现了很多错误消息,如下所示:
UIWindowScene仅在iOS 13或更高版本中可用
我该怎么办?
IKK*_*KKA 50
您能否添加如下所示的行代码
第1步:-
@available 出 SceneDelegate.swift
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
//...
}
Run Code Online (Sandbox Code Playgroud)
第2步:-
@available 在 AppDelegate.swift 中的一些方法
// AppDelegate.swift
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
Run Code Online (Sandbox Code Playgroud)
第3步:-
您应该在 AppDelegate.swift 文件中声明window属性,如var window: UIWindow?
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Run Code Online (Sandbox Code Playgroud)
mat*_*att 44
Xcode 11中的模板使用场景委托。场景委托和相关类是iOS 13中的新增功能;它们在iOS 12及更高版本中不存在,并且启动过程有所不同。
为了使从Xcode 11应用模板生成的项目向后兼容,您需要将整个SceneDelegate类以及AppDelegate类中引用UISceneSession的任何方法标记为@available(iOS 13.0, *)。
您还需要window在AppDelegate类中声明一个属性(如果不这样做,则该应用将运行并启动,但屏幕将变为黑色):
var window : UIWindow?
Run Code Online (Sandbox Code Playgroud)
结果是,当此应用程序在iOS 13中运行时,场景委托具有window,但在iOS 12或更低版本中运行时,该应用程序委托具有window-,然后您的其他代码可能需要考虑该因素,以便向下兼容。
| 归档时间: |
|
| 查看次数: |
6354 次 |
| 最近记录: |