vicki753's iOS 基础 - 如何去掉 SceneDelegate

因为需要对低版本的兼容,所以不能直接使用新的api ,SceneDelegate 这个就需要删掉了
主要是因为info.plist文件中有对 SceneDelegate的设置

Screen Shot 2021-05-25 at 4.07.47 PM.png

看到这里有种冲动项改掉 delegate Class Name 为AppDelegate ,我改了,崩掉了

Info.plist configuration "Default Configuration" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName, "AppDelegate", but it does not conform to the UISceneDelegate protocol.

就是说 UISceneDelegate 这个AppDelegate没有实现 UISceneDelegate 方法,如果你把方法移动到AppDelegate中也是可以的,并把UISceneDelegate的< UIWindowSceneDelegate> 放到AppDelegate,方法移到AppDelegate, 以及window添加,就相当于(UISceneDelegate 有的,移到AppDelegate, + info.plist配置修改)也是可以的,直接运行成功

如果不需要这么麻烦,只是为了兼容低版本,直接删掉不需要的就好了,没必要多次一举,以下几个步骤
1、然后这个 Application Scene Manifest 这一栏 删掉了就好了,可以运行不再崩溃

2、SceneDelegate.h和SceneDelegate.m我们也不会用上了,删掉

3、也因为AppDelegate中的两个方法 也是需要 13.0版本的,所以也需要删掉,接下来就差不多可以自由发挥了

- (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 *)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中添加window属性


Screen Shot 2021-05-25 at 4.23.42 PM.png

你可能感兴趣的:(vicki753's iOS 基础 - 如何去掉 SceneDelegate)