Extended the SDWebImageManager `loadImageWithURL:options:progress:completed:` so it also returns the NSData (we will need it later for the GIF images).
- had to add an NSData param to `SDWebImageCompletionWithFinishedBlock `, so to make it simpler see this change for users, renamed the block type to `SDInternalCompletionBlock` - pass the NSData from the ImageCache or the Downloader - updated all classes using this method with the new signature
This commit is contained in:
parent
e775b444ef
commit
aecb13d421
|
@ -46,7 +46,7 @@ static char imageURLKey;
|
|||
|
||||
if (url) {
|
||||
__weak __typeof(self)wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong MKAnnotationView *sself = wself;
|
||||
|
|
|
@ -92,7 +92,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
|||
|
||||
typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
|
||||
|
||||
typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
|
||||
typedef void(^SDInternalCompletionBlock)(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
|
||||
|
||||
typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
|
||||
|
||||
|
@ -212,7 +212,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
- (id <SDWebImageOperation>)loadImageWithURL:(NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
|
||||
completed:(SDInternalCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Saves image to cache for given URL
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
- (id <SDWebImageOperation>)loadImageWithURL:(NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock {
|
||||
completed:(SDInternalCompletionBlock)completedBlock {
|
||||
// Invoking this method without a completedBlock is pointless
|
||||
NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead");
|
||||
|
||||
|
@ -144,7 +144,7 @@
|
|||
if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
||||
dispatch_main_sync_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
|
||||
completedBlock(nil, nil, error, SDImageCacheTypeNone, YES, url);
|
||||
});
|
||||
return operation;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@
|
|||
dispatch_main_sync_safe(^{
|
||||
// If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image
|
||||
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
|
||||
completedBlock(cachedImage, nil, cacheType, YES, url);
|
||||
completedBlock(cachedImage, cachedData, nil, cacheType, YES, url);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@
|
|||
} else if (error) {
|
||||
dispatch_main_sync_safe(^{
|
||||
if (strongOperation && !strongOperation.isCancelled) {
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, finished, url);
|
||||
completedBlock(nil, nil, error, SDImageCacheTypeNone, finished, url);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -234,7 +234,7 @@
|
|||
|
||||
dispatch_main_sync_safe(^{
|
||||
if (strongOperation && !strongOperation.isCancelled) {
|
||||
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||
completedBlock(transformedImage, downloadedData, nil, SDImageCacheTypeNone, finished, url);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -245,7 +245,7 @@
|
|||
|
||||
dispatch_main_sync_safe(^{
|
||||
if (strongOperation && !strongOperation.isCancelled) {
|
||||
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||
completedBlock(downloadedImage, downloadedData, nil, SDImageCacheTypeNone, finished, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -273,7 +273,7 @@
|
|||
dispatch_main_sync_safe(^{
|
||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||
if (strongOperation && !strongOperation.isCancelled) {
|
||||
completedBlock(cachedImage, nil, cacheType, YES, url);
|
||||
completedBlock(cachedImage, cachedData, nil, cacheType, YES, url);
|
||||
}
|
||||
});
|
||||
@synchronized (self.runningOperations) {
|
||||
|
@ -284,7 +284,7 @@
|
|||
dispatch_main_sync_safe(^{
|
||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||
if (strongOperation && !weakOperation.isCancelled) {
|
||||
completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
|
||||
completedBlock(nil, nil, nil, SDImageCacheTypeNone, YES, url);
|
||||
}
|
||||
});
|
||||
@synchronized (self.runningOperations) {
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
||||
if (index >= self.prefetchURLs.count) return;
|
||||
self.requestedCount++;
|
||||
[self.manager loadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
[self.manager loadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!finished) return;
|
||||
self.finishedCount++;
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ static char imageURLStorageKey;
|
|||
self.imageURLStorage[@(state)] = url;
|
||||
|
||||
__weak __typeof(self)wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong UIButton *sself = wself;
|
||||
|
@ -117,7 +117,7 @@ static char imageURLStorageKey;
|
|||
|
||||
if (url) {
|
||||
__weak __typeof(self)wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong UIButton *sself = wself;
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
if (url) {
|
||||
__weak __typeof(self)wself = self;
|
||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe (^
|
||||
{
|
||||
|
|
|
@ -59,7 +59,7 @@ static char TAG_ACTIVITY_SHOW;
|
|||
}
|
||||
|
||||
__weak __typeof(self)wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
[wself removeActivityIndicator];
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
|
@ -113,7 +113,7 @@ static char TAG_ACTIVITY_SHOW;
|
|||
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSURL *logoImageURL in arrayOfURLs) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong UIImageView *sself = wself;
|
||||
|
|
Loading…
Reference in New Issue