解决AppDelegate.m内部代码过于臃肿的问题
- 绝大多数的项目AppDelegate.m内都有冗长臃肿的代码
- 多种与启动相关的业务代码相互混淆在一起
- 可读性差,不方便管理,高耦合
解决方案
- 根据业务种类的不同创建一一对应的分类管理
以配置rootController与推送业务为例子
1.创建AppDelegate分类

root.png

push3F427D0.png
2.在AppDelegate分类内实现业务逻辑

10001-8C24-30A8415130EE.png
#import "AppDelegate.h"
#import "AppDelegate+RootVIewCtrl.h"
#import "AppDelegate+Push.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self configRootView]; //配置window与根控制器相关
[self configPush]; //配置推送业务相关
return YES;
}
#import "AppDelegate+RootVIewCtrl.h"
@implementation AppDelegate (RootVIewCtrl)
- (void)configRootView{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
//self.window.rootViewController = rootVC;
}
@end
#import "AppDelegate+Push.h"
@implementation AppDelegate (Push)
- (void)configPush {
//推送配置
}
@end
网友评论