序言
该功能的实现是基于 Aspects 框架实现的,之前已经有对该框架做了深入的讲解,感兴趣的朋友可以先行阅读。iOS-Aspects框架详解
实现
调用Aspects框架的aspect_hookSelector方法对方法进行 hook
[BaseViewController aspect_hookSelector:@selector(viewDidLoad) withOptions:AspectPositionBefore usingBlock:^(id aspectInfo) {
BaseViewController *vc = aspectInfo.instance;
if (!vc.dataModel) vc.dataModel = [DataCubeModel new];
// 未设置别名使用控制器名
if (vc.dataModel.alias_page == nil) {
NSDictionary *dict = [DataCubeTracker sharedIntance].cubeMapp;
[dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
__block BOOL isContain = NO;
if ([obj containsString:@","]) {
NSArray *objArr = [obj componentsSeparatedByString:@","];
[objArr enumerateObjectsUsingBlock:^(NSString *obj1, NSUInteger idx,