Always making callbacks using the main thread.

Even if using the downloader directly without SDWebImageManager.
This commit is contained in:
Matej Bukovinski 2012-11-19 11:47:19 +01:00 committed by Olivier Poitrey
parent ab185ea6e8
commit 9a3aff4851
2 changed files with 17 additions and 16 deletions

View File

@ -146,12 +146,17 @@
{
dispatch_async(self.queue, ^
{
self.expectedSize = response.expectedContentLength > 0 ? (NSUInteger)response.expectedContentLength : 0;
self.imageData = [NSMutableData.alloc initWithCapacity:self.expectedSize];
if (self.progressBlock)
NSUInteger expected = response.expectedContentLength > 0 ? (NSUInteger)response.expectedContentLength : 0;
self.imageData = [NSMutableData.alloc initWithCapacity:expected];
self.expectedSize = expected;
dispatch_async(dispatch_get_main_queue(), ^
{
self.progressBlock(0, self.expectedSize);
}
if (self.progressBlock)
{
self.progressBlock(0, expected);
}
});
});
}
else
@ -238,10 +243,13 @@
CFRelease(imageSource);
}
if (self.progressBlock)
dispatch_async(dispatch_get_main_queue(), ^
{
self.progressBlock(self.imageData.length, self.expectedSize);
}
if (self.progressBlock)
{
self.progressBlock(self.imageData.length, self.expectedSize);
}
});
});
}

View File

@ -97,14 +97,7 @@
SDWebImageDownloaderOptions downloaderOptions = 0;
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:^(NSUInteger receivedSize, long long expectedSize)
{
dispatch_async(dispatch_get_main_queue(), ^
{
progressBlock(receivedSize, expectedSize);
});
}
completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
__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(), ^
{