Merge branch 'master' into new_cancel_logic
Conflicts: SDWebImage/MKAnnotationView+WebCache.m SDWebImage/UIButton+WebCache.m SDWebImage/UIImageView+HighlightedWebCache.h SDWebImage/UIImageView+HighlightedWebCache.m SDWebImage/UIImageView+WebCache.m
This commit is contained in:
commit
5615cf12de
|
@ -372,7 +372,7 @@
|
|||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
||||
}
|
||||
|
||||
cell.textLabel.text = [NSString stringWithFormat:@"Image #%d", indexPath.row];
|
||||
cell.textLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
|
||||
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[cell.imageView setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]]
|
||||
placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
|
||||
|
|
|
@ -384,20 +384,20 @@
|
|||
53922DA9148C562D0056699D /* Categories */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */,
|
||||
ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */,
|
||||
5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */,
|
||||
5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */,
|
||||
53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */,
|
||||
53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */,
|
||||
A18A6CC5172DC28500419892 /* UIImage+GIF.h */,
|
||||
A18A6CC6172DC28500419892 /* UIImage+GIF.m */,
|
||||
53EDFB911762547C00698166 /* UIImage+WebP.h */,
|
||||
53EDFB921762547C00698166 /* UIImage+WebP.m */,
|
||||
535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */,
|
||||
535699B515113E7300A4C397 /* MKAnnotationView+WebCache.m */,
|
||||
5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */,
|
||||
5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */,
|
||||
53922D93148C56230056699D /* UIButton+WebCache.h */,
|
||||
53922D94148C56230056699D /* UIButton+WebCache.m */,
|
||||
A18A6CC5172DC28500419892 /* UIImage+GIF.h */,
|
||||
A18A6CC6172DC28500419892 /* UIImage+GIF.m */,
|
||||
53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */,
|
||||
53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */,
|
||||
53EDFB911762547C00698166 /* UIImage+WebP.h */,
|
||||
53EDFB921762547C00698166 /* UIImage+WebP.m */,
|
||||
ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */,
|
||||
ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */,
|
||||
53922D95148C56230056699D /* UIImageView+WebCache.h */,
|
||||
53922D96148C56230056699D /* UIImageView+WebCache.m */,
|
||||
AB615301192DA24600A2D8E9 /* UIView+WebCacheOperation.h */,
|
||||
|
|
|
@ -18,82 +18,86 @@
|
|||
* Get the current image URL.
|
||||
*
|
||||
* Note that because of the limitations of categories this property can get out of sync
|
||||
* if you use setImage: directly.
|
||||
* if you use sd_setImage: directly.
|
||||
*/
|
||||
- (NSURL *)imageURL;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @see setImageWithURL:placeholderImage:options:
|
||||
* @see sd_setImageWithURL:placeholderImage:options:
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Cancel the current download
|
||||
|
@ -101,3 +105,16 @@
|
|||
- (void)cancelCurrentImageLoad;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface MKAnnotationView (WebCacheDeprecated)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`");
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,33 +14,31 @@ static char imageURLKey;
|
|||
|
||||
@implementation MKAnnotationView (WebCache)
|
||||
|
||||
- (NSURL *)imageURL;
|
||||
{
|
||||
- (NSURL *)imageURL {
|
||||
return objc_getAssociatedObject(self, &imageURLKey);
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url
|
||||
{
|
||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self cancelCurrentImageLoad];
|
||||
|
||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
|
@ -48,7 +46,7 @@ static char imageURLKey;
|
|||
|
||||
if (url) {
|
||||
__weak MKAnnotationView *wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong MKAnnotationView *sself = wself;
|
||||
|
@ -57,11 +55,18 @@ static char imageURLKey;
|
|||
sself.image = image;
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
[self setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"];
|
||||
} else {
|
||||
dispatch_main_async_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||
if (completedBlock) {
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,3 +75,44 @@ static char imageURLKey;
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation MKAnnotationView (WebCacheDeprecated)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -6,5 +6,14 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSData (ImageContentType)
|
||||
|
||||
/**
|
||||
* Compute the content type for an image data
|
||||
*
|
||||
* @param data the input data
|
||||
*
|
||||
* @return the content type as string (i.e. image/jpeg, image/gif)
|
||||
*/
|
||||
+ (NSString *)contentTypeForImageData:(NSData *)data;
|
||||
|
||||
@end
|
||||
|
|
|
@ -56,7 +56,13 @@ extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
|
|||
#define dispatch_main_sync_safe(block)\
|
||||
if ([NSThread isMainThread]) {\
|
||||
block();\
|
||||
}\
|
||||
else {\
|
||||
} else {\
|
||||
dispatch_sync(dispatch_get_main_queue(), block);\
|
||||
}
|
||||
|
||||
#define dispatch_main_async_safe(block)\
|
||||
if ([NSThread isMainThread]) {\
|
||||
block();\
|
||||
} else {\
|
||||
dispatch_async(dispatch_get_main_queue(), block);\
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
#endif
|
||||
|
||||
inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
|
||||
if (!image) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ([image.images count] > 0) {
|
||||
NSMutableArray *scaledImages = [NSMutableArray array];
|
||||
|
||||
|
|
|
@ -127,8 +127,8 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
|
||||
options:options
|
||||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||
if (!wself) return;
|
||||
SDWebImageDownloader *sself = wself;
|
||||
if (!sself) return;
|
||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
||||
for (NSDictionary *callbacks in callbacksForURL) {
|
||||
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
||||
|
@ -136,8 +136,8 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
}
|
||||
}
|
||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
if (!wself) return;
|
||||
SDWebImageDownloader *sself = wself;
|
||||
if (!sself) return;
|
||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
||||
if (finished) {
|
||||
[sself removeCallbacksForURL:url];
|
||||
|
@ -148,13 +148,15 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
}
|
||||
}
|
||||
cancelled:^{
|
||||
if (!wself) return;
|
||||
SDWebImageDownloader *sself = wself;
|
||||
if (!sself) return;
|
||||
[sself removeCallbacksForURL:url];
|
||||
}];
|
||||
|
||||
if (options & SDWebImageDownloaderHighPriority) {
|
||||
operation.queuePriority = NSOperationQueuePriorityHigh;
|
||||
} else if (options & SDWebImageDownloaderLowPriority) {
|
||||
operation.queuePriority = NSOperationQueuePriorityLow;
|
||||
}
|
||||
|
||||
[wself.downloadQueue addOperation:operation];
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "SDWebImageDecoder.h"
|
||||
#import "UIImage+MultiFormat.h"
|
||||
#import <ImageIO/ImageIO.h>
|
||||
#import "SDWebImageManager.h"
|
||||
|
||||
@interface SDWebImageDownloaderOperation () {
|
||||
BOOL _executing;
|
||||
|
@ -285,7 +286,8 @@
|
|||
|
||||
if (partialImageRef) {
|
||||
UIImage *image = [UIImage imageWithCGImage:partialImageRef scale:1 orientation:orientation];
|
||||
UIImage *scaledImage = [self scaledImageForKey:self.request.URL.absoluteString image:image];
|
||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||
UIImage *scaledImage = [self scaledImageForKey:key image:image];
|
||||
image = [UIImage decodedImageWithImage:scaledImage];
|
||||
CGImageRelease(partialImageRef);
|
||||
dispatch_main_sync_safe(^{
|
||||
|
@ -353,7 +355,8 @@
|
|||
|
||||
UIImage *image = [UIImage sd_imageWithData:self.imageData];
|
||||
|
||||
image = [self scaledImageForKey:self.request.URL.absoluteString image:image];
|
||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||
image = [self scaledImageForKey:key image:image];
|
||||
|
||||
if (!image.images) // Do not force decod animated GIFs
|
||||
{
|
||||
|
|
|
@ -77,9 +77,9 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
|||
SDWebImageDelayPlaceholder = 1 << 9
|
||||
};
|
||||
|
||||
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType);
|
||||
typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
|
||||
|
||||
typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished);
|
||||
typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
|
||||
|
||||
|
||||
@class SDWebImageManager;
|
||||
|
@ -126,7 +126,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
[manager downloadWithURL:imageURL
|
||||
options:0
|
||||
progress:nil
|
||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (image) {
|
||||
// do something with image
|
||||
}
|
||||
|
@ -188,10 +188,10 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
*
|
||||
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
|
||||
*/
|
||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url
|
||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(SDWebImageCompletedWithFinishedBlock)completedBlock;
|
||||
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Saves image to cache for given URL
|
||||
|
@ -225,3 +225,24 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
- (NSString *)cacheKeyForURL:(NSURL *)url;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`");
|
||||
typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`");
|
||||
|
||||
|
||||
@interface SDWebImageManager (Deprecated)
|
||||
|
||||
/**
|
||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||
*
|
||||
* @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:`
|
||||
*/
|
||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`");
|
||||
|
||||
@end
|
||||
|
|
|
@ -71,7 +71,10 @@
|
|||
return [self.imageCache diskImageExistsWithKey:key];
|
||||
}
|
||||
|
||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock {
|
||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock {
|
||||
// Invoking this method without a completedBlock is pointless
|
||||
NSParameterAssert(completedBlock);
|
||||
|
||||
|
@ -97,7 +100,7 @@
|
|||
if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
||||
dispatch_main_sync_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, YES);
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
|
||||
});
|
||||
return operation;
|
||||
}
|
||||
|
@ -121,7 +124,7 @@
|
|||
dispatch_main_sync_safe(^{
|
||||
// If image was found in the cache bug 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(image, nil, cacheType, YES);
|
||||
completedBlock(image, nil, cacheType, YES, url);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -143,12 +146,12 @@
|
|||
id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) {
|
||||
if (weakOperation.isCancelled) {
|
||||
dispatch_main_sync_safe(^{
|
||||
completedBlock(nil, nil, SDImageCacheTypeNone, finished);
|
||||
completedBlock(nil, nil, SDImageCacheTypeNone, finished, url);
|
||||
});
|
||||
}
|
||||
else if (error) {
|
||||
dispatch_main_sync_safe(^{
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, finished);
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, finished, url);
|
||||
});
|
||||
|
||||
if (error.code != NSURLErrorNotConnectedToInternet && error.code != NSURLErrorCancelled && error.code != NSURLErrorTimedOut) {
|
||||
|
@ -174,7 +177,7 @@
|
|||
}
|
||||
|
||||
dispatch_main_sync_safe(^{
|
||||
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished);
|
||||
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -184,7 +187,7 @@
|
|||
}
|
||||
|
||||
dispatch_main_sync_safe(^{
|
||||
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished);
|
||||
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +208,7 @@
|
|||
}
|
||||
else if (image) {
|
||||
dispatch_main_sync_safe(^{
|
||||
completedBlock(image, nil, cacheType, YES);
|
||||
completedBlock(image, nil, cacheType, YES, url);
|
||||
});
|
||||
@synchronized (self.runningOperations) {
|
||||
[self.runningOperations removeObject:operation];
|
||||
|
@ -214,7 +217,7 @@
|
|||
else {
|
||||
// Image not in cache and download disallowed by delegate
|
||||
dispatch_main_sync_safe(^{
|
||||
completedBlock(nil, nil, SDImageCacheTypeNone, YES);
|
||||
completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
|
||||
});
|
||||
@synchronized (self.runningOperations) {
|
||||
[self.runningOperations removeObject:operation];
|
||||
|
@ -245,6 +248,7 @@
|
|||
|
||||
@end
|
||||
|
||||
|
||||
@implementation SDWebImageCombinedOperation
|
||||
|
||||
- (void)setCancelBlock:(void (^)())cancelBlock {
|
||||
|
@ -269,3 +273,21 @@
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation SDWebImageManager (Deprecated)
|
||||
|
||||
// deprecated method, uses the non deprecated method
|
||||
// adapter for the completion block
|
||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock {
|
||||
return [self downloadImageWithURL:url
|
||||
options:options
|
||||
progress:progressBlock
|
||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType, finished);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
*
|
||||
* @param imagePrefetcher The current image prefetcher
|
||||
* @param imageURL The image url that was prefetched
|
||||
* @param finishedCount The total number of images that were prefetched
|
||||
* @param totalCount The total number of images that need to be prefetched
|
||||
* @param finishedCount The total number of images that were prefetched (successful or not)
|
||||
* @param totalCount The total number of images that were to be prefetched
|
||||
*/
|
||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
||||
|
||||
/**
|
||||
* Called when all images are prefetched.
|
||||
* @param imagePrefetcher The current image prefetcher
|
||||
* @param totalCount The total number of images that need to be prefetched
|
||||
* @param totalCount The total number of images that were prefetched (whether successful or not)
|
||||
* @param skippedCount The total number of images that were skipped
|
||||
*/
|
||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
||||
|
@ -78,7 +78,9 @@
|
|||
* and skips images for failed downloads and proceed to the next image in the list
|
||||
*
|
||||
* @param urls list of URLs to prefetch
|
||||
* @param progressBlock block to be called when progress updates
|
||||
* @param progressBlock block to be called when progress updates;
|
||||
* first parameter is the number of completed (successful or not) requests,
|
||||
* second parameter is the total number of images originally requested to be prefetched
|
||||
* @param completionBlock block to be called when prefetching is completed
|
||||
*/
|
||||
- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock;
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
||||
if (index >= self.prefetchURLs.count) return;
|
||||
self.requestedCount++;
|
||||
[self.manager downloadWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
[self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!finished) return;
|
||||
self.finishedCount++;
|
||||
|
||||
|
@ -88,7 +88,7 @@
|
|||
[self startPrefetchingAtIndex:self.requestedCount];
|
||||
});
|
||||
}
|
||||
else if (self.finishedCount + self.skippedCount == self.requestedCount) {
|
||||
else if (self.finishedCount == self.requestedCount) {
|
||||
[self reportStatus];
|
||||
if (self.completionBlock) {
|
||||
self.completionBlock(self.finishedCount, self.skippedCount);
|
||||
|
|
|
@ -29,159 +29,165 @@
|
|||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @see setImageWithURL:placeholderImage:options:
|
||||
* @see sd_setImageWithURL:placeholderImage:options:
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
*/
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url` and a placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @see setImageWithURL:placeholderImage:options:
|
||||
* @see sd_setImageWithURL:placeholderImage:options:
|
||||
*/
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param completedBlock A block object to be executed after the request operation
|
||||
* completed. This block has no return value and takes three argument: the requested
|
||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`, placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param completedBlock A block object to be executed after the request operation
|
||||
* completed. This block has no return value and takes three argument: the requested
|
||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param completedBlock A block object to be executed after the request operation
|
||||
* completed. This block has no return value and takes three argument: the requested
|
||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Cancel the current image download
|
||||
|
@ -194,3 +200,24 @@
|
|||
- (void)cancelBackgroundImageLoadForState:(UIControlState)state;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UIButton (WebCacheDeprecated)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`");
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`");
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`");
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`");
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`");
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`");
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`");
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`");
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`");
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`");
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,45 +14,41 @@ static char imageURLStorageKey;
|
|||
|
||||
@implementation UIButton (WebCache)
|
||||
|
||||
- (NSURL *)currentImageURL;
|
||||
{
|
||||
- (NSURL *)currentImageURL {
|
||||
NSURL *url = self.imageURLStorage[@(self.state)];
|
||||
|
||||
if (!url)
|
||||
{
|
||||
if (!url) {
|
||||
url = self.imageURLStorage[@(UIControlStateNormal)];
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
- (NSURL *)imageURLForState:(UIControlState)state;
|
||||
{
|
||||
- (NSURL *)imageURLForState:(UIControlState)state {
|
||||
return self.imageURLStorage[@(state)];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state
|
||||
{
|
||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
|
||||
[self setImage:placeholder forState:state];
|
||||
[self cancelImageLoadForState:state];
|
||||
|
@ -60,13 +56,20 @@ static char imageURLStorageKey;
|
|||
if (!url) {
|
||||
[self.imageURLStorage removeObjectForKey:@(state)];
|
||||
|
||||
dispatch_main_async_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||
if (completedBlock) {
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
self.imageURLStorage[@(state)] = url;
|
||||
|
||||
__weak UIButton *wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong UIButton *sself = wself;
|
||||
|
@ -75,41 +78,41 @@ static char imageURLStorageKey;
|
|||
[sself setImage:image forState:state];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
[self setImageLoadOperation:operation forState:state];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self cancelImageLoadForState:state];
|
||||
|
||||
[self setBackgroundImage:placeholder forState:state];
|
||||
|
||||
if (url) {
|
||||
__weak UIButton *wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong UIButton *sself = wself;
|
||||
|
@ -118,11 +121,18 @@ static char imageURLStorageKey;
|
|||
[sself setBackgroundImage:image forState:state];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
[self setBackgroundImageLoadOperation:operation forState:state];
|
||||
} else {
|
||||
dispatch_main_async_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||
if (completedBlock) {
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,8 +152,7 @@ static char imageURLStorageKey;
|
|||
[self cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
|
||||
}
|
||||
|
||||
- (NSMutableDictionary *)imageURLStorage;
|
||||
{
|
||||
- (NSMutableDictionary *)imageURLStorage {
|
||||
NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
||||
if (!storage)
|
||||
{
|
||||
|
@ -155,3 +164,80 @@ static char imageURLStorageKey;
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UIButton (WebCacheDeprecated)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#import "UIImage+MultiFormat.h"
|
||||
#import "UIImage+GIF.h"
|
||||
#import "NSData+ImageContentType.h"
|
||||
#import <ImageIO/ImageIO.h>
|
||||
|
||||
#ifdef SD_WEBP
|
||||
#import "UIImage+WebP.h"
|
||||
|
@ -30,10 +31,82 @@
|
|||
#endif
|
||||
else {
|
||||
image = [[UIImage alloc] initWithData:data];
|
||||
UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data];
|
||||
if (orientation != UIImageOrientationUp) {
|
||||
image = [UIImage imageWithCGImage:image.CGImage
|
||||
scale:image.scale
|
||||
orientation:orientation];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
+(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
|
||||
UIImageOrientation result = UIImageOrientationUp;
|
||||
CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
|
||||
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
|
||||
if (properties) {
|
||||
CFTypeRef val;
|
||||
int exifOrientation;
|
||||
val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
|
||||
if (val) {
|
||||
CFNumberGetValue(val, kCFNumberIntType, &exifOrientation);
|
||||
result = [self sd_exifOrientationToiOSOrientation:exifOrientation];
|
||||
} // else - if it's not set it remains at up
|
||||
CFRelease((CFTypeRef) properties);
|
||||
} else {
|
||||
//NSLog(@"NO PROPERTIES, FAIL");
|
||||
}
|
||||
CFRelease(imageSource);
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma EXIF orientation tag converter
|
||||
// Convert an EXIF image orientation to an iOS one.
|
||||
// reference see here: http://sylvana.net/jpegcrop/exif_orientation.html
|
||||
+ (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation {
|
||||
UIImageOrientation orientation = UIImageOrientationUp;
|
||||
switch (exifOrientation) {
|
||||
case 1:
|
||||
orientation = UIImageOrientationUp;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
orientation = UIImageOrientationDown;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
orientation = UIImageOrientationLeft;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
orientation = UIImageOrientationRight;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
orientation = UIImageOrientationUpMirrored;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
orientation = UIImageOrientationDownMirrored;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
orientation = UIImageOrientationLeftMirrored;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
orientation = UIImageOrientationRightMirrored;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return orientation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -18,62 +18,66 @@
|
|||
/**
|
||||
* Set the imageView `highlightedImage` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url;
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param progressBlock A block called while image is downloading
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Cancel the current download
|
||||
|
@ -81,3 +85,14 @@
|
|||
- (void)cancelCurrentHighlightedImageLoad;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UIImageView (HighlightedWebCacheDeprecated)
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
|
||||
|
||||
@end
|
||||
|
|
|
@ -13,32 +13,28 @@
|
|||
|
||||
@implementation UIImageView (HighlightedWebCache)
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url {
|
||||
[self setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url {
|
||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
||||
[self setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self cancelCurrentHighlightedImageLoad];
|
||||
|
||||
if (url) {
|
||||
__weak UIImageView *wself = self;
|
||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url
|
||||
options:options
|
||||
progress:progressBlock
|
||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
||||
{
|
||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe (^
|
||||
{
|
||||
|
@ -48,11 +44,18 @@
|
|||
[wself setNeedsLayout];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
[self setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
|
||||
} else {
|
||||
dispatch_main_async_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||
if (completedBlock) {
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,3 +64,40 @@
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UIImageView (HighlightedWebCacheDeprecated)
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url {
|
||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
autorelease];
|
||||
}
|
||||
|
||||
// Here we use the provided setImageWithURL: method to load the web image
|
||||
// Here we use the provided sd_setImageWithURL: method to load the web image
|
||||
// Ensure you use a placeholder image otherwise cells will be initialized with no image
|
||||
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
||||
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
||||
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
||||
|
||||
cell.textLabel.text = @"My Text";
|
||||
|
@ -48,82 +48,85 @@
|
|||
* Get the current image URL.
|
||||
*
|
||||
* Note that because of the limitations of categories this property can get out of sync
|
||||
* if you use setImage: directly.
|
||||
* if you use sd_setImage: directly.
|
||||
*/
|
||||
- (NSURL *)imageURL;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @see setImageWithURL:placeholderImage:options:
|
||||
* @see sd_setImageWithURL:placeholderImage:options:
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand is asynchronous and cached.
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
|
@ -134,12 +137,13 @@
|
|||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param progressBlock A block called while image is downloading
|
||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Download an array of images and starts them in an animation loop
|
||||
|
@ -156,3 +160,17 @@
|
|||
- (void)cancelCurrentAnimationImagesLoad;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UIImageView (WebCacheDeprecated)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`");
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`");
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,31 +14,31 @@ static char imageURLKey;
|
|||
|
||||
@implementation UIImageView (WebCache)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url {
|
||||
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
[self cancelCurrentImageLoad];
|
||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
self.image = placeholder;
|
||||
|
@ -49,7 +49,7 @@ static char imageURLKey;
|
|||
|
||||
if (url) {
|
||||
__weak UIImageView *wself = self;
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
if (!wself) return;
|
||||
|
@ -63,28 +63,33 @@ static char imageURLKey;
|
|||
}
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
[self setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
|
||||
} else {
|
||||
dispatch_main_async_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||
if (completedBlock) {
|
||||
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (NSURL *)imageURL;
|
||||
{
|
||||
- (NSURL *)imageURL {
|
||||
return objc_getAssociatedObject(self, &imageURLKey);
|
||||
}
|
||||
|
||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs
|
||||
{
|
||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
||||
[self cancelCurrentAnimationImagesLoad];
|
||||
__weak UIImageView *wself = self;
|
||||
|
||||
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSURL *logoImageURL in arrayOfURLs) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe(^{
|
||||
__strong UIImageView *sself = wself;
|
||||
|
@ -117,3 +122,55 @@ static char imageURLKey;
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UIImageView (WebCacheDeprecated)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||
if (completedBlock) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue