更新Xcode11之后,删除Main.storyboard,且删除Main storyboard file base name之后运行报错
Xcode11自动新增了一个SceneDelegate文件,查找了一下官方文档WWDC2019:Optimizing App Launch 发现iOS13中appdelegate的职责发现了改变:
iOS13之前,Appdelegate的职责全权处理App生命周期和UI生命周期;
iOS13之后,Appdelegate的职责是:
1、处理 App 生命周期
2、新的 Scene Session 生命周期
那UI的生命周期呢?交给新增的Scene Delegate处理, Appdelegate不在负责UI生命周期,所有UI生命周期交给SceneDelegate处理
因此Xcode11之后,除了与以前一样,要在项目Info.plist删除Main storyboard file base name(:指定应用启动时加载的storyboard文件名);或者Main nib file base name(:指定应用启动时加载的xib文件名)之外, 还要删除SceneDelegate的StoryboardName
或者在General----Deployment Info----Main Interface中清除Main.storyboard
在AppDelegate中自定义UIWindow,代码不起作用
因此初始化window方法需要改变: 现在不再在Appdelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions进行初始化
而是在SceneDelegate中初始化了
-
- (
void)scene:(
UIScene *)scene willConnectToSession:(
UISceneSession *)session options:(
UISceneConnectionOptions *)connectionOptions {
-
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
-
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
-
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
-
-
UIWindowScene *windowScene = (
UIWindowScene *)scene;
-
self.window = [[
UIWindow alloc] initWithWindowScene:windowScene];
-
MainViewController *launchVC = [[MainViewController alloc] init];
-
self.window.rootViewController = launchVC;
-
self.window.backgroundColor = [
UIColor whiteColor];
-
[
self.window makeKeyAndVisible];
-
}
SceneDelegate 生命周期
-
- (
void)scene:(
UIScene *)scene willConnectToSession:(
UISceneSession *)session options:(
UISceneConnectionOptions *)connectionOptions {
-
NSLog(
@"场景加载完成");
-
// iOS 12上的 application(_:didFinishLaunchingWithOptions:) 函数的作用最相似。当将场景添加到app中时scene(_:willConnectTo:options:)函数会被调用的。
-
}
-
- (
void)sceneDidDisconnect:(
UIScene *)scene {
-
NSLog(
@"场景已经断开连接");
-
// (注意,以后它可能被重新连接)
-
}
-
- (
void)sceneDidBecomeActive:(
UIScene *)scene {
-
NSLog(
@"已经从后台进入前台 ");
-
//(例如从应用切换器中选择场景)
-
}
-
- (
void)sceneWillResignActive:(
UIScene *)scene {
-
NSLog(
@"即将从前台进入后台");
-
//(例如通过切换器切换到另一个场景)
-
}
-
- (
void)sceneWillEnterForeground:(
UIScene *)scene {
-
NSLog(
@"即将从后台进入前台");
-
}
-
- (
void)sceneDidEnterBackground:(
UIScene *)scene {
-
NSLog(
@"已经从前台进入后台");
-
}
转载:https://blog.csdn.net/MinggeQingchun/article/details/116305591