想要监控所有页面的访问情况,根据念茜的这篇文章Objective-C的hook方案(一): Method Swizzling
添加了UIViewController的类别,在+(void)load 里添加了 下面的代码,在工程里加,每次页面访问都能监控到,但是如果自己做一个framework,把这些代码放到framework,然后在工程里调用framework,就不会执行了。但是bugly却能监听到访问了那些页面,debug bugly的load方法,发现执行了bugly 添加的UIViewController的类别(如下图),我添加的却不会执行到。请问有那位大神知道怎么做的吗?
-
(void)load {
Class class=[self class];
SEL origMethod=@selector(viewWillAppear:);
SEL swizzleMethod=@selector(myviewWillAppear:);Method ori_Method2 = class_getInstanceMethod(class, origMethod);
Method my_Method2 = class_getInstanceMethod(class, swizzleMethod);
method_exchangeImplementations(ori_Method2, my_Method2);
}
-(void) myviewWillAppear:(BOOL)animated {
NSLog(@"%s",func);
}