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.
|
* Get the current image URL.
|
||||||
*
|
*
|
||||||
* Note that because of the limitations of categories this property can get out of sync
|
* 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;
|
- (NSURL *)imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* 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.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url;
|
- (void)sd_setImageWithURL:(NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* 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.
|
* @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.
|
* 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 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`.
|
* 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 completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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.
|
* 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 url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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.
|
* 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 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.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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
|
* Cancel the current download
|
||||||
|
@ -101,3 +105,16 @@
|
||||||
- (void)cancelCurrentImageLoad;
|
- (void)cancelCurrentImageLoad;
|
||||||
|
|
||||||
@end
|
@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)
|
@implementation MKAnnotationView (WebCache)
|
||||||
|
|
||||||
- (NSURL *)imageURL;
|
- (NSURL *)imageURL {
|
||||||
{
|
|
||||||
return objc_getAssociatedObject(self, &imageURLKey);
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url
|
- (void)sd_setImageWithURL:(NSURL *)url {
|
||||||
{
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 completed: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];
|
[self cancelCurrentImageLoad];
|
||||||
|
|
||||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
@ -48,7 +46,7 @@ static char operationKey;
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak MKAnnotationView *wself = self;
|
__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;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong MKAnnotationView *sself = wself;
|
__strong MKAnnotationView *sself = wself;
|
||||||
|
@ -57,7 +55,7 @@ static char operationKey;
|
||||||
sself.image = image;
|
sself.image = image;
|
||||||
}
|
}
|
||||||
if (completedBlock && finished) {
|
if (completedBlock && finished) {
|
||||||
completedBlock(image, error, cacheType);
|
completedBlock(image, error, cacheType, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
|
@ -75,3 +73,44 @@ static char operationKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@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.
|
* Store an image into memory and disk cache at the given key.
|
||||||
*
|
*
|
||||||
* @param image The image to store
|
* @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;
|
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an image into memory and optionally disk cache at the given key.
|
* 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 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
|
||||||
* @param toDisk Store the image to disk cache if YES
|
* @param toDisk Store the image to disk cache if YES
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
- (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.
|
* 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 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
|
* @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
|
* instead of converting the given image object into a storable/compressed image format in order
|
||||||
* to save quality and CPU
|
* to save quality and CPU
|
||||||
* @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
|
||||||
* @param toDisk Store the image to disk cache if YES
|
* @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;
|
- (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
|
* 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)
|
* @param completionBlock An block that should be executed after the image has been removed (optional)
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion;
|
- (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
|
* 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
|
* @param fromDisk Also remove cache entry from disk if YES
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
|
- (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
|
* 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
|
* @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)
|
* @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;
|
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion;
|
||||||
|
|
|
@ -129,17 +129,17 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
|
||||||
*
|
*
|
||||||
* @see SDWebImageDownloaderDelegate
|
* @see SDWebImageDownloaderDelegate
|
||||||
*
|
*
|
||||||
* @param url The URL to the image to download
|
* @param url The URL to the image to download
|
||||||
* @param options The options to be used for this download
|
* @param options The options to be used for this download
|
||||||
* @param progressBlock A block called repeatedly while the image is downloading
|
* @param progressBlock A block called repeatedly while the image is downloading
|
||||||
* @param completedBlock A block called once the download is completed.
|
* @param completedBlock A block called once the download is completed.
|
||||||
* If the download succeeded, the image parameter is set, in case of error,
|
* 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
|
* error parameter is set with the error. The last parameter is always YES
|
||||||
* if SDWebImageDownloaderProgressiveDownload isn't use. With the
|
* if SDWebImageDownloaderProgressiveDownload isn't use. With the
|
||||||
* SDWebImageDownloaderProgressiveDownload option, this block is called
|
* SDWebImageDownloaderProgressiveDownload option, this block is called
|
||||||
* repeatedly with the partial image object and the finished argument set to NO
|
* 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
|
* 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.
|
* set to YES. In case of error, the finished argument is always YES.
|
||||||
*
|
*
|
||||||
* @return A cancellable SDWebImageOperation
|
* @return A cancellable SDWebImageOperation
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -77,9 +77,9 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
||||||
SDWebImageDelayPlaceholder = 1 << 9
|
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;
|
@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.
|
* Controls which image should be downloaded when the image is not found in the cache.
|
||||||
*
|
*
|
||||||
* @param imageManager The current `SDWebImageManager`
|
* @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.
|
* @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.
|
* NOTE: This method is called from a global queue in order to not to block the main thread.
|
||||||
*
|
*
|
||||||
* @param imageManager The current `SDWebImageManager`
|
* @param imageManager The current `SDWebImageManager`
|
||||||
* @param image The image to transform
|
* @param image The image to transform
|
||||||
* @param imageURL The url of the image to transform
|
* @param imageURL The url of the image to transform
|
||||||
*
|
*
|
||||||
* @return The transformed image object.
|
* @return The transformed image object.
|
||||||
*/
|
*/
|
||||||
|
@ -126,7 +126,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
[manager downloadWithURL:imageURL
|
[manager downloadWithURL:imageURL
|
||||||
options:0
|
options:0
|
||||||
progress:nil
|
progress:nil
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (image) {
|
if (image) {
|
||||||
// do something with 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.
|
* 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 url The URL to the image
|
||||||
* @param options A mask to specify options to use for this request
|
* @param options A mask to specify options to use for this request
|
||||||
* @param progressBlock A block called while image is downloading
|
* @param progressBlock A block called while image is downloading
|
||||||
* @param completedBlock A block called when operation has been completed.
|
* @param completedBlock A block called when operation has been completed.
|
||||||
*
|
*
|
||||||
* This parameter is required.
|
* 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
|
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
|
||||||
*/
|
*/
|
||||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageCompletedWithFinishedBlock)completedBlock;
|
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves image to cache for given URL
|
* Saves image to cache for given URL
|
||||||
*
|
*
|
||||||
* @param image The image to cache
|
* @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;
|
- (NSString *)cacheKeyForURL:(NSURL *)url;
|
||||||
|
|
||||||
@end
|
@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];
|
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
|
// Invoking this method without a completedBlock is pointless
|
||||||
NSParameterAssert(completedBlock);
|
NSParameterAssert(completedBlock);
|
||||||
|
|
||||||
|
@ -97,7 +100,7 @@
|
||||||
if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
||||||
completedBlock(nil, error, SDImageCacheTypeNone, YES);
|
completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
|
||||||
});
|
});
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +124,7 @@
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
// If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image
|
// 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.
|
// 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) {
|
id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) {
|
||||||
if (weakOperation.isCancelled) {
|
if (weakOperation.isCancelled) {
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(nil, nil, SDImageCacheTypeNone, finished);
|
completedBlock(nil, nil, SDImageCacheTypeNone, finished, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (error) {
|
else if (error) {
|
||||||
dispatch_main_sync_safe(^{
|
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) {
|
if (error.code != NSURLErrorNotConnectedToInternet && error.code != NSURLErrorCancelled && error.code != NSURLErrorTimedOut) {
|
||||||
|
@ -174,7 +177,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished);
|
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -184,7 +187,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished);
|
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +208,7 @@
|
||||||
}
|
}
|
||||||
else if (image) {
|
else if (image) {
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(image, nil, cacheType, YES);
|
completedBlock(image, nil, cacheType, YES, url);
|
||||||
});
|
});
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
[self.runningOperations removeObject:operation];
|
[self.runningOperations removeObject:operation];
|
||||||
|
@ -214,7 +217,7 @@
|
||||||
else {
|
else {
|
||||||
// Image not in cache and download disallowed by delegate
|
// Image not in cache and download disallowed by delegate
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
completedBlock(nil, nil, SDImageCacheTypeNone, YES);
|
completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
|
||||||
});
|
});
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
[self.runningOperations removeObject:operation];
|
[self.runningOperations removeObject:operation];
|
||||||
|
@ -245,6 +248,7 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation SDWebImageCombinedOperation
|
@implementation SDWebImageCombinedOperation
|
||||||
|
|
||||||
- (void)setCancelBlock:(void (^)())cancelBlock {
|
- (void)setCancelBlock:(void (^)())cancelBlock {
|
||||||
|
@ -269,3 +273,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@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.
|
* Called when an image was prefetched.
|
||||||
*
|
*
|
||||||
* @param imagePrefetcher The current image prefetcher
|
* @param imagePrefetcher The current image prefetcher
|
||||||
* @param imageURL The image url that was prefetched
|
* @param imageURL The image url that was prefetched
|
||||||
* @param finishedCount The total number of images that were prefetched (successful or not)
|
* @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 totalCount The total number of images that were to be prefetched
|
||||||
*/
|
*/
|
||||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when all images are prefetched.
|
* Called when all images are prefetched.
|
||||||
* @param imagePrefetcher The current image prefetcher
|
* @param imagePrefetcher The current image prefetcher
|
||||||
* @param totalCount The total number of images that were prefetched (whether successful or not)
|
* @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 skippedCount The total number of images that were skipped
|
||||||
*/
|
*/
|
||||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
||||||
|
|
||||||
|
@ -77,8 +77,10 @@
|
||||||
* currently one image is downloaded at a time,
|
* currently one image is downloaded at a time,
|
||||||
* and skips images for failed downloads and proceed to the next image in the list
|
* and skips images for failed downloads and proceed to the next image in the list
|
||||||
*
|
*
|
||||||
* @param urls list of URLs to prefetch
|
* @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 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
|
* @param completionBlock block to be called when prefetching is completed
|
||||||
*/
|
*/
|
||||||
- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock;
|
- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock;
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
||||||
if (index >= self.prefetchURLs.count) return;
|
if (index >= self.prefetchURLs.count) return;
|
||||||
self.requestedCount++;
|
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;
|
if (!finished) return;
|
||||||
self.finishedCount++;
|
self.finishedCount++;
|
||||||
|
|
||||||
|
|
|
@ -29,159 +29,165 @@
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* 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.
|
* @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.
|
* 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 state The state that uses the specified title. The values are described in UIControlState.
|
* @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 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.
|
* 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 state The state that uses the specified title. The values are described in UIControlState.
|
* @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 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`.
|
* 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.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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.
|
* 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 url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @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 placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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.
|
* 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 state The state that uses the specified title. The values are described in UIControlState.
|
* @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 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.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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`.
|
* 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.
|
* @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.
|
* 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 url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @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 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.
|
* 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 url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @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 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`.
|
* 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.
|
* @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
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* completed. This block has no return value and takes three argument: the requested
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
* 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.
|
* 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 url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @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 placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param completedBlock A block object to be executed after the request operation
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* completed. This block has no return value and takes three argument: the requested
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
* 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.
|
* 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 url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @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.
|
||||||
* @param completedBlock A block object to be executed after the request operation
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* completed. This block has no return value and takes three argument: the requested
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
* `UIImage` object, the `NSError` object describing error that occurred, and an
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
* `SDImageCacheType` enum describing the source of the image obtained from.
|
* 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
|
* Cancel the current download
|
||||||
|
@ -189,3 +195,24 @@
|
||||||
- (void)cancelCurrentImageLoad;
|
- (void)cancelCurrentImageLoad;
|
||||||
|
|
||||||
@end
|
@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)
|
@implementation UIButton (WebCache)
|
||||||
|
|
||||||
- (NSURL *)currentImageURL;
|
- (NSURL *)currentImageURL {
|
||||||
{
|
|
||||||
NSURL *url = self.imageURLStorage[@(self.state)];
|
NSURL *url = self.imageURLStorage[@(self.state)];
|
||||||
|
|
||||||
if (!url)
|
if (!url)
|
||||||
|
@ -26,33 +25,31 @@ static char operationKey;
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)imageURLForState:(UIControlState)state;
|
- (NSURL *)imageURLForState:(UIControlState)state {
|
||||||
{
|
|
||||||
return self.imageURLStorage[@(state)];
|
return self.imageURLStorage[@(state)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||||
{
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
[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 {
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed: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 {
|
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed: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 setImage:placeholder forState:state];
|
||||||
[self cancelCurrentImageLoad];
|
[self cancelCurrentImageLoad];
|
||||||
|
@ -66,7 +63,7 @@ static char operationKey;
|
||||||
self.imageURLStorage[@(state)] = url;
|
self.imageURLStorage[@(state)] = url;
|
||||||
|
|
||||||
__weak UIButton *wself = self;
|
__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;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong UIButton *sself = wself;
|
__strong UIButton *sself = wself;
|
||||||
|
@ -75,41 +72,41 @@ static char operationKey;
|
||||||
[sself setImage:image forState:state];
|
[sself setImage:image forState:state];
|
||||||
}
|
}
|
||||||
if (completedBlock && finished) {
|
if (completedBlock && finished) {
|
||||||
completedBlock(image, error, cacheType);
|
completedBlock(image, error, cacheType, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
[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 {
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed: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 {
|
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed: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 cancelCurrentImageLoad];
|
||||||
|
|
||||||
[self setBackgroundImage:placeholder forState:state];
|
[self setBackgroundImage:placeholder forState:state];
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak UIButton *wself = self;
|
__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;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong UIButton *sself = wself;
|
__strong UIButton *sself = wself;
|
||||||
|
@ -118,7 +115,7 @@ static char operationKey;
|
||||||
[sself setBackgroundImage:image forState:state];
|
[sself setBackgroundImage:image forState:state];
|
||||||
}
|
}
|
||||||
if (completedBlock && finished) {
|
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);
|
NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
||||||
if (!storage)
|
if (!storage)
|
||||||
{
|
{
|
||||||
|
@ -149,3 +145,80 @@ static char operationKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@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`.
|
* 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 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.
|
* 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.
|
* @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`.
|
* 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 url The url for the image.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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.
|
* 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.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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.
|
* 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.
|
* @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 progressBlock A block called while image is downloading
|
||||||
* @param completedBlock A block called when operation has been completed. This block as no return value
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
* 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
|
* 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.
|
* 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
|
@end
|
||||||
|
|
|
@ -13,47 +13,80 @@ static char operationKey;
|
||||||
|
|
||||||
@implementation UIImageView (HighlightedWebCache)
|
@implementation UIImageView (HighlightedWebCache)
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url {
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url {
|
||||||
[self setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
||||||
[self setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setHighlightedImageWithURL:url options:options progress:nil completed: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];
|
[self cancelCurrentImageLoad];
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak UIImageView *wself = self;
|
__weak UIImageView *wself = self;
|
||||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url
|
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
options:options
|
if (!wself) return;
|
||||||
progress:progressBlock
|
dispatch_main_sync_safe (^
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
|
{
|
||||||
{
|
if (!wself) return;
|
||||||
if (!wself) return;
|
if (image) {
|
||||||
dispatch_main_sync_safe (^
|
wself.highlightedImage = image;
|
||||||
{
|
[wself setNeedsLayout];
|
||||||
if (!wself) return;
|
}
|
||||||
if (image) {
|
if (completedBlock && finished) {
|
||||||
wself.highlightedImage = image;
|
completedBlock(image, error, cacheType, url);
|
||||||
[wself setNeedsLayout];
|
}
|
||||||
}
|
});
|
||||||
if (completedBlock && finished) {
|
}];
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}];
|
|
||||||
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@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];
|
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
|
// Ensure you use a placeholder image otherwise cells will be initialized with no image
|
||||||
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
placeholderImage:[UIImage imageNamed:@"placeholder"]];
|
||||||
|
|
||||||
cell.textLabel.text = @"My Text";
|
cell.textLabel.text = @"My Text";
|
||||||
return cell;
|
return cell;
|
||||||
|
@ -48,98 +48,102 @@
|
||||||
* Get the current image URL.
|
* Get the current image URL.
|
||||||
*
|
*
|
||||||
* Note that because of the limitations of categories this property can get out of sync
|
* 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;
|
- (NSURL *)imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* 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.
|
||||||
*/
|
*/
|
||||||
- (void)setImageWithURL:(NSURL *)url;
|
- (void)sd_setImageWithURL:(NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* 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.
|
* @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.
|
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
*
|
*
|
||||||
* The download 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 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.
|
||||||
* @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
|
- (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
|
* 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
|
* 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.
|
* 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
|
* Download an array of images and starts them in an animation loop
|
||||||
|
@ -156,3 +160,17 @@
|
||||||
- (void)cancelCurrentArrayLoad;
|
- (void)cancelCurrentArrayLoad;
|
||||||
|
|
||||||
@end
|
@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)
|
@implementation UIImageView (WebCache)
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url {
|
- (void)sd_setImageWithURL:(NSURL *)url {
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed: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 {
|
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
||||||
[self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed: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];
|
[self cancelCurrentImageLoad];
|
||||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
self.image = placeholder;
|
self.image = placeholder;
|
||||||
|
@ -50,7 +50,7 @@ static char operationArrayKey;
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak UIImageView *wself = self;
|
__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;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
|
@ -64,7 +64,7 @@ static char operationArrayKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (completedBlock && finished) {
|
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);
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs
|
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
||||||
{
|
|
||||||
[self cancelCurrentArrayLoad];
|
[self cancelCurrentArrayLoad];
|
||||||
__weak UIImageView *wself = self;
|
__weak UIImageView *wself = self;
|
||||||
|
|
||||||
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
|
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (NSURL *logoImageURL in arrayOfURLs) {
|
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;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong UIImageView *sself = wself;
|
__strong UIImageView *sself = wself;
|
||||||
|
@ -130,3 +128,55 @@ static char operationArrayKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@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