Xcode11删除SceneDelegate

作者: 遛遛食 | 来源:发表于2020-05-20 15:12 被阅读0次

    在Xcode11创建的项目会包含SceneDelegate这个类,苹果主要想用这个类来监听APP的生命周期,但是很多老项目还是使用AppDelegate来操作,所以我们就来把SceneDelegate删除掉,重新来使用AppDelegate监听。

    删除info.plist中Application Scene Manifest字段

    这样系统就会认为不使用SceneDelegate这个类了

    删除SceneDelegate类

    直接把整个类删除即可

    修改AppDelegate类

    AppDelegate需要增加window属性,并增加window视图和根控制器

    .h
    @property (nonatomic,strong) UIWindow *window;
    
    .m
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        self.window.backgroundColor = UIColor.whiteColor;
        self.window.rootViewController = [ViewController new];
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

    把AppDelegate中下面的两个方法删除掉

    这样就重新使用AppDelegate来控制APP的生命周期了。

    相关文章

      网友评论

        本文标题:Xcode11删除SceneDelegate

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