Implemented progress callbacks and related fixes.
This commit is contained in:
parent
2e8c02556a
commit
ab185ea6e8
|
@ -13,8 +13,8 @@
|
|||
NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification";
|
||||
NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
|
||||
|
||||
NSString *const kProgressCallbackKey = @"completed";
|
||||
NSString *const kCompletedCallbackKey = @"completed";
|
||||
static NSString *const kProgressCallbackKey = @"progress";
|
||||
static NSString *const kCompletedCallbackKey = @"completed";
|
||||
|
||||
@interface SDWebImageDownloader ()
|
||||
|
||||
|
@ -107,7 +107,7 @@ NSString *const kCompletedCallbackKey = @"completed";
|
|||
{
|
||||
if (!wself) return;
|
||||
SDWebImageDownloader *sself = wself;
|
||||
NSArray *callbacksForURL = [sself callbacksForURL:url remove:YES];
|
||||
NSArray *callbacksForURL = [sself callbacksForURL:url remove:NO];
|
||||
for (NSDictionary *callbacks in callbacksForURL)
|
||||
{
|
||||
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
||||
|
|
|
@ -148,6 +148,10 @@
|
|||
{
|
||||
self.expectedSize = response.expectedContentLength > 0 ? (NSUInteger)response.expectedContentLength : 0;
|
||||
self.imageData = [NSMutableData.alloc initWithCapacity:self.expectedSize];
|
||||
if (self.progressBlock)
|
||||
{
|
||||
self.progressBlock(0, self.expectedSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -234,6 +238,10 @@
|
|||
|
||||
CFRelease(imageSource);
|
||||
}
|
||||
if (self.progressBlock)
|
||||
{
|
||||
self.progressBlock(self.imageData.length, self.expectedSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,14 @@
|
|||
SDWebImageDownloaderOptions downloaderOptions = 0;
|
||||
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
|
||||
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)
|
||||
__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)
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue