|
| 1 | +// |
| 2 | +// QCloudAbstractRequest+Quality.m |
| 3 | +// QCloudCOSXML |
| 4 | +// |
| 5 | +// Created by erichmzhang(张恒铭) on 2018/8/24. |
| 6 | +// |
| 7 | + |
| 8 | +#import "QCloudAbstractRequest+Quality.h" |
| 9 | +#import <objc/runtime.h> |
| 10 | +#import "QualityDataUploader.h" |
| 11 | +@implementation QCloudAbstractRequest (Quality) |
| 12 | ++ (void) load{ |
| 13 | + static dispatch_once_t onceToken; |
| 14 | + dispatch_once(&onceToken, ^{ |
| 15 | + [self exchangeImplementation]; |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | ++ (void)exchangeImplementation { |
| 20 | + Class class = [self class]; |
| 21 | + SEL originalSelector = @selector(__notifySuccess:); |
| 22 | + SEL swizzledSelector = @selector(__quality__notifySuccess:); |
| 23 | + Method originNotifySuccessMethod = class_getInstanceMethod(class, @selector(__notifySuccess:)); |
| 24 | + Method swizzedNotifySuccessMethod = class_getInstanceMethod(class, @selector(__quality__notifySuccess:)); |
| 25 | + |
| 26 | + method_exchangeImplementations(originNotifySuccessMethod, swizzedNotifySuccessMethod); |
| 27 | + |
| 28 | + |
| 29 | + Method originNotifyErrorMethod = class_getInstanceMethod(class, @selector(__notifyError:)); |
| 30 | + Method swizzedNotifyErrorMethod = class_getInstanceMethod(class, @selector(__quality__notifyError:)); |
| 31 | + method_exchangeImplementations(originNotifyErrorMethod, swizzedNotifyErrorMethod); |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +- (void)__quality__notifySuccess:(id)object { |
| 39 | + [self __quality__notifySuccess:(id)object]; |
| 40 | + [QualityDataUploader trackRequestSuccessWithType:self.class]; |
| 41 | +} |
| 42 | + |
| 43 | +- (void)__quality__notifyError:(NSError *)error { |
| 44 | + [self __quality__notifyError:error]; |
| 45 | + [QualityDataUploader trackRequestFailWithError:error]; |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +@end |
0 commit comments