// // SDImageCache+Resize.m // iCemarose // // Created by Sanchew on 2017/9/1. // Copyright © 2017年 kollway. All rights reserved. // #import "SDImageCache+Resize.h" #import <Aspects/Aspects.h> #import <RegexKitLite/RegexKitLite.h> #import <SDWebImage/SDWebImageDownloader.h> #import <AFNetworking/AFNetworking.h> @implementation SDImageCache (Resize) + (void)load { [self aspect_hookSelector:@selector(queryDiskCacheForKey:done:) withOptions:AspectPositionInstead usingBlock:^(id<AspectInfo> info){ SDWebImageQueryCompletedBlock real = info.arguments[1]; SDWebImageQueryCompletedBlock block = ^(UIImage *image, SDImageCacheType cacheType) { NSString *reg = @"imageView2/2/w/(\\d+)/h/(\\d+)"; NSArray *sizeM = @[@"150",@"300",@"500",@"1000"]; NSString *imageUrl = info.arguments[0]; if (!image && [imageUrl isMatchedByRegex:reg]) { NSArray *sizes = [imageUrl captureComponentsMatchedByRegex:reg]; NSUInteger si = [sizeM indexOfObject:sizes[1]]; if (sizeM.count > si + 1) { NSString *cs = sizeM[si + 1]; NSString *niu = [imageUrl stringByReplacingOccurrencesOfRegex:reg withString:[NSString stringWithFormat:@"imageView2/2/w/%@/h/%@",cs,cs]]; [info.originalInvocation.target queryDiskCacheForKey:niu done:real]; return; } } real(image,cacheType); }; [info.originalInvocation setArgument:&block atIndex:3]; [info.originalInvocation invoke]; } error:nil]; } @end //@implementation SDWebImageDownloader (log) ////- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock // //+ (void)load { // [self aspect_hookSelector:@selector(downloadImageWithURL:options:progress:completed:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info) { // NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; // NSString *url = [NSString stringWithFormat:@"http://localhost:3001?c=%@",info.arguments[0]]; // NSURL *URL = [NSURL URLWithString:url]; // NSURLRequest *request = [NSURLRequest requestWithURL:URL]; // // NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:nil]; // [dataTask resume]; // } error:nil]; //} // //@end