Authored by Matej Bukovinski
Committed by Olivier Poitrey

Calling completion callbacks in the main thread.

- made sure this is true even if the downloader is used on its own
- SDWebImageManager doesn't need to perform a dispatch to the main thread any longer
... ... @@ -237,7 +237,13 @@
{
UIImage *image = [UIImage decodedImageWithImage:SDScaledImageForPath(self.request.URL.absoluteString, [UIImage imageWithCGImage:partialImageRef])];
CGImageRelease(partialImageRef);
if (self.completedBlock) self.completedBlock(image, nil, nil, NO);
dispatch_async(dispatch_get_main_queue(), ^
{
if (self.completedBlock)
{
self.completedBlock(image, nil, nil, NO);
}
});
}
}
... ...
... ... @@ -99,24 +99,21 @@
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
{
dispatch_async(dispatch_get_main_queue(), ^
completedBlock(downloadedImage, error, SDImageCacheTypeNone, finished);
if (error)
{
[self.failedURLs addObject:url];
}
else if (downloadedImage && finished)
{
[self.imageCache storeImage:downloadedImage imageData:data forKey:key toDisk:YES];
}
if (finished)
{
completedBlock(downloadedImage, error, SDImageCacheTypeNone, finished);
if (error)
{
[self.failedURLs addObject:url];
}
else if (downloadedImage && finished)
{
[self.imageCache storeImage:downloadedImage imageData:data forKey:key toDisk:YES];
}
if (finished)
{
[self.runningOperations removeObject:operation];
}
});
[self.runningOperations removeObject:operation];
}
}];
operation.cancelBlock = ^{[subOperation cancel];};
}
... ...