Merge pull request #770 from bpoplauschi/completion_with_url
Pass imageURL in completedBlock
This commit is contained in:
commit
a8a69ab9b6
|
@ -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 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 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 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 url The url for the image.
|
||||
* @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 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 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 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 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 operationKey;
|
|||
|
||||
@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 operationKey;
|
|||
|
||||
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,7 +55,7 @@ static char operationKey;
|
|||
sself.image = image;
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
@ -75,3 +73,44 @@ static char operationKey;
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -73,15 +73,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
|
|||
* Store an image into memory and disk cache at the given key.
|
||||
*
|
||||
* @param image The image to store
|
||||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
*/
|
||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
|
||||
|
||||
/**
|
||||
* Store an image into memory and optionally disk cache at the given key.
|
||||
*
|
||||
* @param image The image to store
|
||||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param image The image to store
|
||||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param toDisk Store the image to disk cache if YES
|
||||
*/
|
||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
||||
|
@ -89,13 +89,13 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
|
|||
/**
|
||||
* Store an image into memory and optionally disk cache at the given key.
|
||||
*
|
||||
* @param image The image to store
|
||||
* @param image The image to store
|
||||
* @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage
|
||||
* @param imageData The image data as returned by the server, this representation will be used for disk storage
|
||||
* instead of converting the given image object into a storable/compressed image format in order
|
||||
* to save quality and CPU
|
||||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param toDisk Store the image to disk cache if YES
|
||||
* @param imageData The image data as returned by the server, this representation will be used for disk storage
|
||||
* instead of converting the given image object into a storable/compressed image format in order
|
||||
* to save quality and CPU
|
||||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param toDisk Store the image to disk cache if YES
|
||||
*/
|
||||
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
||||
|
||||
|
@ -131,7 +131,7 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
|
|||
/**
|
||||
* Remove the image from memory and disk cache synchronously
|
||||
*
|
||||
* @param key The unique image cache key
|
||||
* @param key The unique image cache key
|
||||
* @param completionBlock An block that should be executed after the image has been removed (optional)
|
||||
*/
|
||||
- (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion;
|
||||
|
@ -139,7 +139,7 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
|
|||
/**
|
||||
* Remove the image from memory and optionally disk cache synchronously
|
||||
*
|
||||
* @param key The unique image cache key
|
||||
* @param key The unique image cache key
|
||||
* @param fromDisk Also remove cache entry from disk if YES
|
||||
*/
|
||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
|
||||
|
@ -147,8 +147,8 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
|
|||
/**
|
||||
* Remove the image from memory and optionally disk cache synchronously
|
||||
*
|
||||
* @param key The unique image cache key
|
||||
* @param fromDisk Also remove cache entry from disk if YES
|
||||
* @param key The unique image cache key
|
||||
* @param fromDisk Also remove cache entry from disk if YES
|
||||
* @param completionBlock An block that should be executed after the image has been removed (optional)
|
||||
*/
|
||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion;
|
||||
|
|
|
@ -129,17 +129,17 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
|
|||
*
|
||||
* @see SDWebImageDownloaderDelegate
|
||||
*
|
||||
* @param url The URL to the image to download
|
||||
* @param options The options to be used for this download
|
||||
* @param progressBlock A block called repeatedly while the image is downloading
|
||||
* @param url The URL to the image to download
|
||||
* @param options The options to be used for this download
|
||||
* @param progressBlock A block called repeatedly while the image is downloading
|
||||
* @param completedBlock A block called once the download is completed.
|
||||
* If the download succeeded, the image parameter is set, in case of error,
|
||||
* error parameter is set with the error. The last parameter is always YES
|
||||
* if SDWebImageDownloaderProgressiveDownload isn't use. With the
|
||||
* SDWebImageDownloaderProgressiveDownload option, this block is called
|
||||
* repeatedly with the partial image object and the finished argument set to NO
|
||||
* before to be called a last time with the full image and finished argument
|
||||
* set to YES. In case of error, the finished argument is always YES.
|
||||
* If the download succeeded, the image parameter is set, in case of error,
|
||||
* error parameter is set with the error. The last parameter is always YES
|
||||
* if SDWebImageDownloaderProgressiveDownload isn't use. With the
|
||||
* SDWebImageDownloaderProgressiveDownload option, this block is called
|
||||
* repeatedly with the partial image object and the finished argument set to NO
|
||||
* before to be called a last time with the full image and finished argument
|
||||
* set to YES. In case of error, the finished argument is always YES.
|
||||
*
|
||||
* @return A cancellable SDWebImageOperation
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
@ -92,7 +92,7 @@ typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *err
|
|||
* Controls which image should be downloaded when the image is not found in the cache.
|
||||
*
|
||||
* @param imageManager The current `SDWebImageManager`
|
||||
* @param imageURL The url of the image to be downloaded
|
||||
* @param imageURL The url of the image to be downloaded
|
||||
*
|
||||
* @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
|
||||
*/
|
||||
|
@ -103,8 +103,8 @@ typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *err
|
|||
* NOTE: This method is called from a global queue in order to not to block the main thread.
|
||||
*
|
||||
* @param imageManager The current `SDWebImageManager`
|
||||
* @param image The image to transform
|
||||
* @param imageURL The url of the image to transform
|
||||
* @param image The image to transform
|
||||
* @param imageURL The url of the image to transform
|
||||
*
|
||||
* @return The transformed image object.
|
||||
*/
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -169,9 +169,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
/**
|
||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||
*
|
||||
* @param url The URL to the image
|
||||
* @param options A mask to specify options to use for this request
|
||||
* @param progressBlock A block called while image is downloading
|
||||
* @param url The URL to the image
|
||||
* @param options A mask to specify options to use for this request
|
||||
* @param progressBlock A block called while image is downloading
|
||||
* @param completedBlock A block called when operation has been completed.
|
||||
*
|
||||
* This parameter is required.
|
||||
|
@ -188,16 +188,16 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
*
|
||||
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
|
||||
*/
|
||||
- (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;
|
||||
|
||||
/**
|
||||
* Saves image to cache for given URL
|
||||
*
|
||||
* @param image The image to cache
|
||||
* @param url The URL to the image
|
||||
* @param url The URL to the image
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -19,17 +19,17 @@
|
|||
* Called when an image was prefetched.
|
||||
*
|
||||
* @param imagePrefetcher The current image prefetcher
|
||||
* @param imageURL The image url that was 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
|
||||
* @param imageURL The image url that was 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 were prefetched (whether successful or not)
|
||||
* @param skippedCount The total number of images that were skipped
|
||||
* @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;
|
||||
|
||||
|
@ -77,8 +77,10 @@
|
|||
* currently one image is downloaded at a time,
|
||||
* 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; 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 urls list of URLs to prefetch
|
||||
* @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++;
|
||||
|
||||
|
|
|
@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 download
|
||||
|
@ -189,3 +195,24 @@
|
|||
- (void)cancelCurrentImageLoad;
|
||||
|
||||
@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,8 +14,7 @@ static char operationKey;
|
|||
|
||||
@implementation UIButton (WebCache)
|
||||
|
||||
- (NSURL *)currentImageURL;
|
||||
{
|
||||
- (NSURL *)currentImageURL {
|
||||
NSURL *url = self.imageURLStorage[@(self.state)];
|
||||
|
||||
if (!url)
|
||||
|
@ -26,33 +25,31 @@ static char operationKey;
|
|||
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 cancelCurrentImageLoad];
|
||||
|
@ -66,7 +63,7 @@ static char operationKey;
|
|||
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 +72,41 @@ static char operationKey;
|
|||
[sself setImage:image forState:state];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (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 cancelCurrentImageLoad];
|
||||
|
||||
[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,7 +115,7 @@ static char operationKey;
|
|||
[sself setBackgroundImage:image forState:state];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
@ -136,8 +133,7 @@ static char operationKey;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSMutableDictionary *)imageURLStorage;
|
||||
{
|
||||
- (NSMutableDictionary *)imageURLStorage {
|
||||
NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
||||
if (!storage)
|
||||
{
|
||||
|
@ -149,3 +145,80 @@ static char operationKey;
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -17,62 +17,77 @@
|
|||
/**
|
||||
* 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 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 url The url for the image.
|
||||
* @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 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 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 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 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;
|
||||
|
||||
@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,47 +13,80 @@ static char operationKey;
|
|||
|
||||
@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 cancelCurrentImageLoad];
|
||||
|
||||
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)
|
||||
{
|
||||
if (!wself) return;
|
||||
dispatch_main_sync_safe (^
|
||||
{
|
||||
if (!wself) return;
|
||||
if (image) {
|
||||
wself.highlightedImage = image;
|
||||
[wself setNeedsLayout];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
}
|
||||
});
|
||||
}];
|
||||
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;
|
||||
if (image) {
|
||||
wself.highlightedImage = image;
|
||||
[wself setNeedsLayout];
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
}
|
||||
|
||||
@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,10 +31,10 @@
|
|||
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"]
|
||||
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
||||
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
||||
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
||||
|
||||
cell.textLabel.text = @"My Text";
|
||||
return cell;
|
||||
|
@ -48,98 +48,102 @@
|
|||
* 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 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;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand 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;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* The downloand 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
|
||||
* 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.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder.
|
||||
*
|
||||
* The downloand 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
|
||||
* 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.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The downloand 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
|
||||
* 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.
|
||||
*/
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @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 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 options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
*/
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
* 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 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 completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder.
|
||||
*
|
||||
* 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 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)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* 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 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)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||
*
|
||||
* 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 progressBlock A block called while image is downloading
|
||||
* @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)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)cancelCurrentArrayLoad;
|
||||
|
||||
@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
|
||||
|
|
|
@ -15,31 +15,31 @@ static char operationArrayKey;
|
|||
|
||||
@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;
|
||||
|
@ -50,7 +50,7 @@ static char operationArrayKey;
|
|||
|
||||
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;
|
||||
|
@ -64,7 +64,7 @@ static char operationArrayKey;
|
|||
}
|
||||
}
|
||||
if (completedBlock && finished) {
|
||||
completedBlock(image, error, cacheType);
|
||||
completedBlock(image, error, cacheType, url);
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
@ -72,20 +72,18 @@ static char operationArrayKey;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSURL *)imageURL;
|
||||
{
|
||||
- (NSURL *)imageURL {
|
||||
return objc_getAssociatedObject(self, &imageURLKey);
|
||||
}
|
||||
|
||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs
|
||||
{
|
||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
||||
[self cancelCurrentArrayLoad];
|
||||
__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;
|
||||
|
@ -130,3 +128,55 @@ static char operationArrayKey;
|
|||
}
|
||||
|
||||
@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