Skip to content

Commit 95337c4

Browse files
author
Olivier Poitrey
committed
Merge pull request SDWebImage#311 from sebreh/master
Detect cancelled parent operation in download operation callback
2 parents 05dd3f4 + d57b92c commit 95337c4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

SDWebImage/SDWebImageManager.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
7676
}
7777

7878
__block SDWebImageCombinedOperation *operation = SDWebImageCombinedOperation.new;
79+
__weak SDWebImageCombinedOperation *weakOperation = operation;
7980

8081
if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && [self.failedURLs containsObject:url]))
8182
{
@@ -108,7 +109,11 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
108109
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
109110
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
110111
{
111-
if (error)
112+
if (weakOperation.cancelled)
113+
{
114+
completedBlock(nil, nil, SDImageCacheTypeNone, finished);
115+
}
116+
else if (error)
112117
{
113118
completedBlock(nil, error, SDImageCacheTypeNone, finished);
114119

0 commit comments

Comments
 (0)