我一直在努力调配NSURLSession class.This的dataTaskWithURL方法是什么,我都试过如何调酒NSURLSession方法dataTaskWithUrl
+ (void)swizzleDataTaskWithRequest {
Class class = [self class];
SEL originalSelector = @selector(dataTaskWithRequest:completionHandler:);
SEL swizzledSelector = @selector(my_dataTaskWithRequest:completionHandler:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod),method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod),method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
- (NSURLSessionDataTask *)my_dataTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSData * __nullable data, NSURLResponse * __nullable response, NSError * __nullable error))completionHandler{
NSLog(@"***************************");
return [self my_dataTaskWithURL:url completionHandler:completionHandler];
}
这my_dataTaskWithURL我想通过自己的完成处理程序,我不知道如何创建
在此先感谢!
[如何调酒NSURLSession类方法dataTaskWithUrl](可能的重复http://stackoverflow.com/questions/35570809/how-to-swizzle-nsurlsession -class-method-datataskwithurl) –