如果我們不開發iPadOS多窗口APP,SceneDelegate窗口管理我們可以不需要直接刪掉就好了。
- 刪除掉info.plist中Application Scene Manifest選項,同時,文件SceneDelegate可刪除可不刪
相關代碼註釋
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
//註釋掉這兩個方法。
如果我們開發iPadOS多窗口APP,SceneDelegate窗口管理我們可以不需要直接刪掉就好了。
1.如果系統是ios13以下的,直接在APPdelegate中進行判斷,因爲ios13,APPdelegate中沒有window屬性,需要重新添加window屬性,創建window
if (@available(ios 13, *)) {
}else{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self detectNetwork];
CLTabbarController *tabbarVC = [[CLTabbarController alloc]init];
CLBaseNavigationController *baseVC = [[CLBaseNavigationController alloc]initWithRootViewController:tabbarVC];
self.window.rootViewController = baseVC;
[self.window makeKeyAndVisible];
}
xcode11新增了SceneDelegate 方法
如果是ios13系統,系統走以下方法
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
// 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 detectNetwork];
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.backgroundColor = [UIColor whiteColor];
CLTabbarController *tabbarVC = [[CLTabbarController alloc]init];
CLBaseNavigationController *baseVC = [[CLBaseNavigationController alloc]initWithRootViewController:tabbarVC];
self.window.rootViewController = baseVC;
[self.window makeKeyAndVisible];
}
剩下就能按照之前項目的步驟進行開發了。