|
@@ -10,7 +10,11 @@ |
|
@@ -10,7 +10,11 @@ |
10
|
#import "SDWebImageDownloaderOperation.h"
|
10
|
#import "SDWebImageDownloaderOperation.h"
|
11
|
#import <ImageIO/ImageIO.h>
|
11
|
#import <ImageIO/ImageIO.h>
|
12
|
|
12
|
|
|
|
13
|
+#define AliCloudHttpDNS
|
|
|
14
|
+
|
|
|
15
|
+#ifdef AliCloudHttpDNS
|
13
|
#import <AlicloudHttpDNS/AlicloudHttpDNS.h>
|
16
|
#import <AlicloudHttpDNS/AlicloudHttpDNS.h>
|
|
|
17
|
+#endif
|
14
|
|
18
|
|
15
|
static NSString *const kProgressCallbackKey = @"progress";
|
19
|
static NSString *const kProgressCallbackKey = @"progress";
|
16
|
static NSString *const kCompletedCallbackKey = @"completed";
|
20
|
static NSString *const kCompletedCallbackKey = @"completed";
|
|
@@ -82,7 +86,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -82,7 +86,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
82
|
#if DEBUG
|
86
|
#if DEBUG
|
83
|
_enableHttpDNS = YES;
|
87
|
_enableHttpDNS = YES;
|
84
|
#else
|
88
|
#else
|
85
|
- _enableHttpDNS = [[[NSUserDefaults standardUserDefaults] stringForKey:@"kUserConfigHttpDNS"] isEqualToString:@"2a90dfa0f37b92aaebf369e9a4d38ba4"];
|
89
|
+ _enableHttpDNS = YES;//[[[NSUserDefaults standardUserDefaults] stringForKey:@"kUserConfigHttpDNS"] isEqualToString:@"2a90dfa0f37b92aaebf369e9a4d38ba4"];
|
86
|
#endif
|
90
|
#endif
|
87
|
}
|
91
|
}
|
88
|
return self;
|
92
|
return self;
|
|
@@ -125,11 +129,12 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -125,11 +129,12 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
125
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
129
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
126
|
__block SDWebImageDownloaderOperation *operation;
|
130
|
__block SDWebImageDownloaderOperation *operation;
|
127
|
__weak __typeof(self)wself = self;
|
131
|
__weak __typeof(self)wself = self;
|
128
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
132
|
+
|
129
|
BOOL useAliDNS = NO;
|
133
|
BOOL useAliDNS = NO;
|
130
|
NSString *imageURLHost = url.host;//获取图片URL的host
|
134
|
NSString *imageURLHost = url.host;//获取图片URL的host
|
131
|
NSURL *newURL = url;
|
135
|
NSURL *newURL = url;
|
132
|
- if (wself.enableHttpDNS && (imageURLHost.length > 0)) {
|
136
|
+#ifdef AliCloudHttpDNS
|
|
|
137
|
+ if (self.enableHttpDNS && (imageURLHost.length > 0)) {
|
133
|
NSArray *ips = [[HttpDnsService sharedInstance] getIpsByHostAsync:imageURLHost];//同步请求ip地址列表
|
138
|
NSArray *ips = [[HttpDnsService sharedInstance] getIpsByHostAsync:imageURLHost];//同步请求ip地址列表
|
134
|
if ([ips isKindOfClass:[NSArray class]] && [ips respondsToSelector:@selector(count)] && ips.count > 0) {
|
139
|
if ([ips isKindOfClass:[NSArray class]] && [ips respondsToSelector:@selector(count)] && ips.count > 0) {
|
135
|
NSString *ipAdress = [ips objectAtIndex:0];
|
140
|
NSString *ipAdress = [ips objectAtIndex:0];
|
|
@@ -142,8 +147,9 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -142,8 +147,9 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
142
|
}
|
147
|
}
|
143
|
}
|
148
|
}
|
144
|
}
|
149
|
}
|
|
|
150
|
+#endif
|
145
|
|
151
|
|
146
|
- [wself addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
|
152
|
+ [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
|
147
|
NSTimeInterval timeoutInterval = wself.downloadTimeout;
|
153
|
NSTimeInterval timeoutInterval = wself.downloadTimeout;
|
148
|
if (timeoutInterval == 0.0) {
|
154
|
if (timeoutInterval == 0.0) {
|
149
|
timeoutInterval = 15.0;
|
155
|
timeoutInterval = 15.0;
|
|
@@ -177,7 +183,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -177,7 +183,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
177
|
}
|
183
|
}
|
178
|
}
|
184
|
}
|
179
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
185
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
180
|
- // NSLog(@"download image completed:url == %@,\nimage = %@",url,image);
|
186
|
+// NSLog(@"download image completed:url == %@,\nimage = %@",url,image);
|
181
|
SDWebImageDownloader *sself = wself;
|
187
|
SDWebImageDownloader *sself = wself;
|
182
|
if (!sself) return;
|
188
|
if (!sself) return;
|
183
|
__block NSArray *callbacksForURL;
|
189
|
__block NSArray *callbacksForURL;
|
|
@@ -218,7 +224,6 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -218,7 +224,6 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
218
|
wself.lastAddedOperation = operation;
|
224
|
wself.lastAddedOperation = operation;
|
219
|
}
|
225
|
}
|
220
|
}];
|
226
|
}];
|
221
|
- });
|
|
|
222
|
|
227
|
|
223
|
return operation;
|
228
|
return operation;
|
224
|
}
|
229
|
}
|