版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_15509071/article/details/81666652
原因是自己没有在要hook的方法的分类里写的而是在另一个类里写的。
Method originalMethod = class_getInstanceMethod([NSClassFromString(@"GXDirectAccessPushClient") class], @selector(notifyAuthenticateSuccess:error:));
Method swizzledMethod = class_getInstanceMethod([Globals class], @selector(notifyAuthenticateSuccess:error:));
method_exchangeImplementations(originalMethod, swizzledMethod);
这样写可以hook到方法但是无法调用系统原来的方法
应该在分类里写
#import <Foundation/Foundation.h>
#import "GXDirectAccessPushClient.h"
@interface GXDirectAccessPushClient (swizz)
@end
#import "GXDirectAccessPushClient+swizz.h"
@implementation GXDirectAccessPushClient(swizz)
- (void)MynotifyAuthenticateSuccess:(_Bool)arg1 error:(id)arg2;
{
[self MynotifyAuthenticateSuccess:arg1 error:arg2];
}
@end
替换
+ (void)load{
{
Method originalMethod = class_getInstanceMethod([NSClassFromString(@"GXDirectAccessPushClient") class], @selector(notifyAuthenticateSuccess:error:));
Method swizzledMethod = class_getInstanceMethod([NSClassFromString(@"GXDirectAccessPushClient") class], @selector(MynotifyAuthenticateSuccess:error:));
method_exchangeImplementations(originalMethod, swizzledMethod);
}