...
|
...
|
@@ -28,34 +28,29 @@ |
|
|
static dispatch_once_t onceToken;
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
@try {
|
|
|
|
|
|
[NSURLSessionTask startTrack];
|
|
|
|
|
|
SEL class_selectors[] = {
|
|
|
SEL selectors[] = {
|
|
|
@selector(dataTaskWithRequest:completionHandler:),
|
|
|
@selector(dataTaskWithURL:completionHandler:),
|
|
|
@selector(uploadTaskWithRequest:fromData:completionHandler:),
|
|
|
@selector(uploadTaskWithRequest:fromFile:completionHandler:),
|
|
|
//@selector(dataTaskWithURL:completionHandler:),
|
|
|
//@selector(uploadTaskWithRequest:fromData:completionHandler:),
|
|
|
//@selector(uploadTaskWithRequest:fromFile:completionHandler:),
|
|
|
@selector(downloadTaskWithRequest:completionHandler:),
|
|
|
@selector(downloadTaskWithURL:completionHandler:),
|
|
|
@selector(downloadTaskWithResumeData:completionHandler:),
|
|
|
//@selector(downloadTaskWithURL:completionHandler:),
|
|
|
//@selector(downloadTaskWithResumeData:completionHandler:),
|
|
|
};
|
|
|
|
|
|
for (NSUInteger index = 0; index < sizeof(class_selectors) / sizeof(SEL); ++index) {
|
|
|
Class selfClass = object_getClass([self class]);
|
|
|
SEL oriSEL = class_selectors[index];
|
|
|
Method oriMethod = class_getClassMethod(selfClass, oriSEL);
|
|
|
SEL cusSEL = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(oriSEL)]);
|
|
|
Method cusMethod = class_getClassMethod(selfClass, cusSEL);
|
|
|
|
|
|
BOOL addSucc = class_addMethod(selfClass, oriSEL, method_getImplementation(cusMethod), method_getTypeEncoding(cusMethod));
|
|
|
if (addSucc) {
|
|
|
class_replaceMethod(selfClass, cusSEL, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
|
|
|
}else {
|
|
|
method_exchangeImplementations(oriMethod, cusMethod);
|
|
|
for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
|
|
|
SEL originalSelector = selectors[index];
|
|
|
SEL swizzledSelector = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(originalSelector)]);
|
|
|
NSError *error = NULL;
|
|
|
[[self class] yh_swizzleMethod:originalSelector
|
|
|
withMethod:swizzledSelector
|
|
|
error:&error];
|
|
|
if (error) {
|
|
|
YHLog(@"Failed to swizzle: on UIControl. Details: %@", error);
|
|
|
error = NULL;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
|
|
}
|
...
|
...
|
@@ -84,7 +79,7 @@ |
|
|
- (NSURLSessionDataTask *)yher_dataTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
|
|
|
{
|
|
|
__block NSURLSessionDataTask *task = [self yher_dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
|
if (completionHandler) {
|
|
|
completionHandler(data,response,error);
|
|
|
}
|
...
|
...
|
@@ -103,7 +98,7 @@ |
|
|
{
|
|
|
|
|
|
__block NSURLSessionUploadTask *task = [self yher_uploadTaskWithRequest:request fromFile:fileURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
|
if (completionHandler) {
|
|
|
completionHandler(data,response,error);
|
|
|
}
|
...
|
...
|
@@ -122,7 +117,7 @@ |
|
|
{
|
|
|
|
|
|
__block NSURLSessionUploadTask *task = [self yher_uploadTaskWithRequest:request fromData:bodyData completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
|
if (completionHandler) {
|
|
|
completionHandler(data,response,error);
|
|
|
}
|
...
|
...
|
@@ -141,7 +136,7 @@ |
|
|
{
|
|
|
|
|
|
__block NSURLSessionDownloadTask *task = [self yher_downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
|
if (completionHandler) {
|
|
|
completionHandler(location,response,error);
|
|
|
}
|
...
|
...
|
@@ -160,7 +155,7 @@ |
|
|
{
|
|
|
|
|
|
__block NSURLSessionDownloadTask *task = [self yher_downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
|
if (completionHandler) {
|
|
|
completionHandler(location,response,error);
|
|
|
}
|
...
|
...
|
@@ -179,7 +174,7 @@ |
|
|
{
|
|
|
|
|
|
__block NSURLSessionDownloadTask *task = [self yher_downloadTaskWithResumeData:resumeData completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
|
if (completionHandler) {
|
|
|
completionHandler(location,response,error);
|
|
|
}
|
...
|
...
|
@@ -211,24 +206,21 @@ |
|
|
dispatch_once(&onceToken, ^{
|
|
|
@try {
|
|
|
|
|
|
SEL class_selectors[] = {
|
|
|
SEL selectors[] = {
|
|
|
@selector(resume),
|
|
|
};
|
|
|
|
|
|
for (NSUInteger index = 0; index < sizeof(class_selectors) / sizeof(SEL); ++index) {
|
|
|
Class selfClass = object_getClass([self class]);
|
|
|
SEL oriSEL = class_selectors[index];
|
|
|
Method oriMethod = class_getClassMethod(selfClass, oriSEL);
|
|
|
SEL cusSEL = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(oriSEL)]);
|
|
|
Method cusMethod = class_getClassMethod(selfClass, cusSEL);
|
|
|
|
|
|
BOOL addSucc = class_addMethod(selfClass, oriSEL, method_getImplementation(cusMethod), method_getTypeEncoding(cusMethod));
|
|
|
if (addSucc) {
|
|
|
class_replaceMethod(selfClass, cusSEL, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
|
|
|
}else {
|
|
|
method_exchangeImplementations(oriMethod, cusMethod);
|
|
|
for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
|
|
|
SEL originalSelector = selectors[index];
|
|
|
SEL swizzledSelector = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(originalSelector)]);
|
|
|
NSError *error = NULL;
|
|
|
[[self class] yh_swizzleMethod:originalSelector
|
|
|
withMethod:swizzledSelector
|
|
|
error:&error];
|
|
|
if (error) {
|
|
|
YHLog(@"Failed to swizzle: on UIControl. Details: %@", error);
|
|
|
error = NULL;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} @catch (NSException *exception) {
|
|
|
YHLog(@"%@ error: %@", self, exception);
|
...
|
...
|
|