xcode11創(chuàng)建項(xiàng)目新增SceneDelegate文件,AppDelegate文件結(jié)構(gòu)也發(fā)生變化碉克,在AppDelegate.h文件中沒(méi)有了window屬性,而是在SceneDelegate.h中,可見(jiàn)AppDelegate不管理window而是交給SceneDelegate。由于這些是ios13新增扩借,所以SceneDelegate在ios13以下的系統(tǒng)是不支持。
那么如果我的App不需要支持多個(gè)Scene 缤至,或者需要兼容 iOS13.0以下的版本怎么辦呢潮罪,其實(shí)很簡(jiǎn)單,移除掉 SceneDelegate 即可领斥。
1嫉到、工程中刪除 SceneDelegate 文件
2、和往常一樣在 AppDelegate 中添加 window 屬性
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
}
3月洛、移除 AppDelegate 中多余的 UIScene 代理方法
移除前
import UIKit
@main
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
}
// MARK: UISceneSession Lifecycle
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)
}
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.
}
}
移除后
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
4何恶、最后在info.plist文件中移除Application Scene Manifest
截屏2022-01-29 下午12.00.06.png
文章持續(xù)更新中、希望對(duì)各位有所幫助膊存、有問(wèn)題可留言 大家共同學(xué)習(xí).