how to hooking a class method?
sayHelloox opened this issue · comments
id object = object_getClass(obj);
[object aspect_...]
can not work for me , What am wrong with me?
id object = object_getClass([TestObject new]);
[object aspect_hookSelector:@selector(testClassMethod) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info){
NSLog(@"Class method ------ hook");
} error:NULL];
//then call method
[TestObject testClassMethod];
// No log "Class method ------ hook" print
id class = object_getClass(obj);
id metaClass = object_getClass(class);
[metaClass aspect_...]
-
import <objc/runtime.h>
-
fetch MetaClass Object
Class settingsMetal = objc_getMetaClass(NSStringFromClass(Settings.class).UTF8String);
-
hook with the MetaClass Object
NSError *error = nil;
[settingsMetal aspect_hookSelector:@selector(hello:) withOptions:AspectPositionBefore usingBlock:^(id info, NSString *hello){} error:&error];
NSLog(@"error %@", error);
Hope this help you !