瘦身-⑥AppDelegate瘦身

必备知识架构-瘦身-⑥AppDelegate瘦身

[toc]

前言

CJModuleManager:CJUIKitDemo-CJBaseUtil-CJModuleManager

1、AppDelegate瘦身

举个更实际的例子,就是你在为AppDelegate瘦身的时候,将AppDelegate上的方法,分散到各自的Manager(UserManager、PushManager、LocationManager等)的时候,就肯定会需要处理这些dele

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

[[CJModuleManager sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; //即一启动,就会去执行所有添加到ModuleManager中所有的 application:application didFinishLaunchingWithOptions:launchOptions 方法

// 设置主窗口,并设置根控制器
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

UIViewController *viewController = [[CTMediator sharedInstance] BBXPLogin_loginViewControllerWithLoginSuccessBlock:loginSuccessBlock getUserInfoSuccessBlock:getUserInfoSuccessBlock];

self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:viewController];

[self.window makeKeyAndVisible];

return YES;
}

// 附:上述AppDelegete.m执行的CJModuleManager.m中方法为
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
for (id<CJModule> module in self.modules) {
if ([module respondsToSelector:_cmd]) {
[module application:application didFinishLaunchingWithOptions:launchOptions];
}
}
return YES;
}

END