美文网首页日常收录
Xcode11 删除SceneDelegate

Xcode11 删除SceneDelegate

作者: 隔墙送来秋千影 | 来源:发表于2020-07-10 11:12 被阅读0次

    iOS13中AppDelegate的职责发现了改变:

    iOS13之前,Appdelegate的职责全权处理App生命周期和UI生命周期;
    iOS13之后,Appdelegate的职责是:
    1、处理 App 生命周期
    2、新的 Scene Session 生命周期

    Appdelegate不在负责UI生命周期,所有UI生命周期交给SceneDelegate处理:

    因此初始化window方法需要改变:
    现在不再Appdelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions进行初始化,转交给SceneDelegate的willConnectToSession:方法进行根控制器设置

    - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        self.window.frame = windowScene.coordinateSpace.bounds;
        self.window.rootViewController = [UITabBarController new];
        [self.window makeKeyAndVisible];
    }
    

    想继续全部使用AppDelegate也是可以的,删除SceneDelegate

    1,直接删除SceneDelegate.h、SceneDelegate.m文件
    2,info.plist文件中删除Application Scene Manifest
    8FD21B88-3FEC-47BA-9B84-AD396C7390D8.png
    3,删除SceneDelegate在AppDelegate中的代理
    #pragma mark - UISceneSession lifecycle
    - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
    }
    
    
    - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
        // 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.h添加@property (strong, nonatomic) UIWindow * window;
    5,没了。

    相关文章

      网友评论

        本文标题:Xcode11 删除SceneDelegate

        本文链接:https://www.haomeiwen.com/subject/eesafktx.html