记一次友盟引起的BUG
2019-01-18 本文已影响0人
HJaycee
友盟SDK有一个私有类UMAOCTools
,在类方法setupHook
中hook了UIViewController的viewDidDisapper
方法。在新的viewDidDisapper
中却没有放行原方法,导致项目中其它地方无法再次hook此方法。
解决办法如下
#import <objc/runtime.h>
@implementation NSObject (FuckUM)
static void swizzleClassMethod(Class c, SEL orig, SEL new) {
Method origMethod = class_getClassMethod(c, orig);
Method newMethod = class_getClassMethod(c, new);
c = object_getClass((id)c);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
+ (void)load {
swizzleClassMethod(NSClassFromString(@"UMAOCTools"), NSSelectorFromString(@"setupHook"), @selector(doNothing));
}
+ (void)doNothing {
}
@end