方案一: 如果我们不开发iPadOS多窗口APP,SceneDelegate窗口管理我们可以不需要直接删掉就好了。
- 删除掉info.plist中Application Scene Manifest选项
- 删除项目中的Scenedelegate.h和Scenedelegate.m
- 删除掉APPdelegate.m中的#pragma mark - UISceneSession lifecycle代码
- 在APPdelegate.h中添加 window属性
@property (strong, nonatomic) UIWindow * window;
方案二:使用iPadOS多窗口,且兼容iOS13以下的
// AppDelegate.h
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@end
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if (@available(iOS 13, *)) {
return YES;
} else {
[self olderSettingFunc];
return YES;
}
return YES;
}
//iOS13以前的设置方法
- (void)olderSettingFunc {
//设置跟视图控制器
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[MainTabBarController alloc] init];
[self.window makeKeyAndVisible];
}
//SceneDelegate.m
//程序完成启动,和didFinishLaunchingWithOptions相似
- (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).
//设置跟视图控制器
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.windowScene = (UIWindowScene *)scene;//Xcode11以后,设置跟视图,要在SceneDelegate中添加这段代码
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[MainTabBarController alloc] init];
[self.window makeKeyAndVisible];
}