...
|
...
|
@@ -10,7 +10,11 @@ |
|
|
#import "SDWebImageDownloaderOperation.h"
|
|
|
#import <ImageIO/ImageIO.h>
|
|
|
|
|
|
#define AliCloudHttpDNS
|
|
|
|
|
|
#ifdef AliCloudHttpDNS
|
|
|
#import <AlicloudHttpDNS/AlicloudHttpDNS.h>
|
|
|
#endif
|
|
|
|
|
|
static NSString *const kProgressCallbackKey = @"progress";
|
|
|
static NSString *const kCompletedCallbackKey = @"completed";
|
...
|
...
|
@@ -82,7 +86,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
|
#if DEBUG
|
|
|
_enableHttpDNS = YES;
|
|
|
#else
|
|
|
_enableHttpDNS = [[[NSUserDefaults standardUserDefaults] stringForKey:@"kUserConfigHttpDNS"] isEqualToString:@"2a90dfa0f37b92aaebf369e9a4d38ba4"];
|
|
|
_enableHttpDNS = YES;//[[[NSUserDefaults standardUserDefaults] stringForKey:@"kUserConfigHttpDNS"] isEqualToString:@"2a90dfa0f37b92aaebf369e9a4d38ba4"];
|
|
|
#endif
|
|
|
}
|
|
|
return self;
|
...
|
...
|
@@ -125,11 +129,12 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
|
|
__block SDWebImageDownloaderOperation *operation;
|
|
|
__weak __typeof(self)wself = self;
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
BOOL useAliDNS = NO;
|
|
|
NSString *imageURLHost = url.host;//获取图片URL的host
|
|
|
NSURL *newURL = url;
|
|
|
if (wself.enableHttpDNS && (imageURLHost.length > 0)) {
|
|
|
#ifdef AliCloudHttpDNS
|
|
|
if (self.enableHttpDNS && (imageURLHost.length > 0)) {
|
|
|
NSArray *ips = [[HttpDnsService sharedInstance] getIpsByHostAsync:imageURLHost];//同步请求ip地址列表
|
|
|
if ([ips isKindOfClass:[NSArray class]] && [ips respondsToSelector:@selector(count)] && ips.count > 0) {
|
|
|
NSString *ipAdress = [ips objectAtIndex:0];
|
...
|
...
|
@@ -142,8 +147,9 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
[wself addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
|
|
|
[self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
|
|
|
NSTimeInterval timeoutInterval = wself.downloadTimeout;
|
|
|
if (timeoutInterval == 0.0) {
|
|
|
timeoutInterval = 15.0;
|
...
|
...
|
@@ -177,7 +183,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
|
}
|
|
|
}
|
|
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
|
|
// NSLog(@"download image completed:url == %@,\nimage = %@",url,image);
|
|
|
// NSLog(@"download image completed:url == %@,\nimage = %@",url,image);
|
|
|
SDWebImageDownloader *sself = wself;
|
|
|
if (!sself) return;
|
|
|
__block NSArray *callbacksForURL;
|
...
|
...
|
@@ -218,7 +224,6 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
|
wself.lastAddedOperation = operation;
|
|
|
}
|
|
|
}];
|
|
|
});
|
|
|
|
|
|
return operation;
|
|
|
}
|
...
|
...
|
|