method swizzing替换系统函数
#ios
#import <objc/runtime.h>
@implementation UIDevice (swizzling)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(systemVersion);
SEL swizzledSelector = @selector(newSystemVersion);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
});
}
- (NSString *)newSystemVersion {
NSLog(@"systemVersion method swizzling");
return [self newSystemVersion];
}
@end