...
|
...
|
@@ -169,8 +169,9 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; |
|
|
for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
|
|
|
progressBlock(0, NSURLResponseUnknownLength, self.request.URL);
|
|
|
}
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:weakSelf];
|
|
|
});
|
|
|
} else {
|
|
|
[self callCompletionBlocksWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}]];
|
...
|
...
|
@@ -201,8 +202,9 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; |
|
|
|
|
|
if (self.dataTask) {
|
|
|
[self.dataTask cancel];
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
|
|
|
});
|
|
|
|
|
|
// As we cancelled the connection, its callback won't be called and thus won't
|
...
|
...
|
@@ -266,8 +268,9 @@ didReceiveResponse:(NSURLResponse *)response |
|
|
|
|
|
self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
|
|
|
self.response = response;
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self];
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:weakSelf];
|
|
|
});
|
|
|
}
|
|
|
else {
|
...
|
...
|
@@ -280,8 +283,9 @@ didReceiveResponse:(NSURLResponse *)response |
|
|
} else {
|
|
|
[self.dataTask cancel];
|
|
|
}
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
|
|
|
});
|
|
|
|
|
|
[self callCompletionBlocksWithError:[NSError errorWithDomain:NSURLErrorDomain code:((NSHTTPURLResponse *)response).statusCode userInfo:nil]];
|
...
|
...
|
@@ -402,10 +406,11 @@ didReceiveResponse:(NSURLResponse *)response |
|
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
|
|
@synchronized(self) {
|
|
|
self.dataTask = nil;
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
|
|
|
if (!error) {
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self];
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:weakSelf];
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
|