iOS新建工程移除默認程序入口SceneDelegate改為AppDelegate

OC版本:

1.先直接刪除SceneDelegate.h/.m文件
2.在AppDelegate.h添加@property (strong, nonatomic) UIWindow * window;屬性

#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow * window;
@end

3.移除UIScene代理
移除之前

#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}

#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.
}//移除
@end

移除之后的效果

#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}
@end

4.最后在info.plist文件中移除Application Scene Manifest

Swift版本
1.先直接刪除SceneDelegate.swift 文件
2.在AppDelegate.swift 中添加 window 屬性 var window: UIWindow?
修改前

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

修改后

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

3.移除UIScene代理

image.png

4.最后在info.plist文件中移除Application Scene Manifest
image.png

5.創(chuàng)建自己的Window

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        //設(shè)置全局顏色
        UITabBar.appearance().tintColor = UIColor.orange
        
        // 創(chuàng)建Window
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = MainTabViewController();
        window?.makeKeyAndVisible()
        return true
    }

更多方法交流可以家魏鑫:lixiaowu1129,一起探討iOS相關(guān)技術(shù)!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容