不用SceneDelegate的操作步骤
1、打开Xcode --> Create New Project...
2、删除Main.storyboard和SceneDelegate.h和SceneDelegate.m(Move to Trash)
3、打开Info.plist,删除Main storyboard file base name 和 Application Scene Mainfest
4、打开AppDelegate.h 添加window属性
@property (nonatomic,strong) UIWindow *window;
5、打开AppDelegate.m,修改 applicationDidFinishLaunchingWithOptions
至如下内容:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor systemPinkColor];
self.window.rootViewController = vc;
return YES;
}
注意:删除一下代码(仅保留上面的didFinishLaunchingWithOptions代码,其他均删除,如果后面需要UIApplicationDelegate中其他方法,可以再加)
#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.
}
6、删除ViewController文件,构建自己的文件构架
7、修改最小支持版本号 minimum Deployments
8、添加应用名称
9、如果要添加后台运行服务,则在Signing&Capabilities中左上角点击 +Capability,搜索background mode
10、添加pch文件 地址:https://www.jianshu.com/p/64526360f8a2
11、图标:提供1024x1024像素图片,放置到网站https://icon.wuruihong.com/#/google_vignette制作
12、Info.plist中添加权限 https://www.jianshu.com/p/166f79ab9963 以及网络请求 App Transport Security Settings (Allow Arbitrary Loads 设置为YES)
13、整理文件目录,找到文件所在目录,手动创建文件夹目录后,将文件夹拉到工程中
14、pod 第三方管理 https://www.jianshu.com/p/0533a4155ab0
15、出现错误 iOS Xcode 15 Sandbox: rsync(xxxx) deny(1) file-write-create
新版本的Xcode 15 编译报该错误 右侧工具栏 项目的workspace 和 pod的 space 都选择为15.0
即可
Build Setting里面搜索user 把User Script Sanboxing 改为NO