在Xcode12中创建新的iOS项目时,会自动添加一个UISceneDelegate。由于我的应用程序应该在iOS 11+ (不支持UISceneDelegate)上可用,所以我不得不删除它。
当然,从info.plist和AppDelegate中删除UISceneDelegate是没有问题的。然而,我想知道我是否必须向application(_: didFinishLaunchingWithOptions)添加任何代码在大多数教程中,我发现这个方法只是留空了,只需要添加var window: UIWindow?。其他来源显示,必须添加一些设置代码。
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
/* Manual Setup */
// let window = UIWindow(frame: UIScreen.main.bounds)
// window.rootViewController = ViewController() // Your initial view controller.
// window.makeKeyAndVisible()
// self.window = window
return true
}
} 在我的测试中,没有任何额外的设置代码,一切都运行得很好。rootViewController是从故事板自动加载的,一切工作正常。
这是巧合吗?这是在后台发生的一些Xcode魔术(如果缺少代码,会自动添加rootVC ),还是我的代码(没有设置)损坏了,最终会在某个非常糟糕的时刻失败
发布于 2021-06-17 22:10:53
你只需要确保
1-删除UISceneDelegate
2-从Info.plist中删除密钥
3-这些方法从AppDelegate中删除
// 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.
}4-向AppDelegate添加var window: UIWindow?
5-确保在Main.storyboard中选择了入口点vc
在此之后,不要担心任何事情,并保留didFinishLaunchingWithOptions为空,就像Xcode 11中没有发生任何更改一样
https://stackoverflow.com/questions/68020796
复制相似问题