iOS 13及以上版本
仅适用于目标版本为13或更高版本。
SceneDelegate
在iOS 13之前不受支持。如果您想要使用SceneDelegate
并且还要支持iOS 13之前的版本,则必须对您的项目进行一些更改。
- 在SceneDelegate.swift文件中的整个类上添加可用性属性。
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
}
- AppDelegate.swift文件有两个新的
SceneDelegate
方法。同样为它们添加可用性属性。
(Note: This is the original text in Chinese. I did not change the meaning or wording in any way.)
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
...
}
@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
...
}
- 最后,在AppDelegate.swift中添加
UIWindow
对象。
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
...
}
iOS 12及更早版本
AppDelegate
需要一个UIWindow
属性。iOS 13在新项目中使用SceneDelegate
。请指定UIWindow
对象并移除SceneDelegate.swift文件。
如果您已从项目中删除了SceneDelegate
,则必须从Info.plist中删除应用程序场景清单字典。
![Info.plist](https://istack.dev59.com/4YlVZ.webp)
SceneDelegate
添加到我的目标中,勾选该框即可解决问题。 - Wayne