SDWebImageManager Class Reference
Inherits from | NSObject |
Declared in | SDWebImageManager.h SDWebImageManager.m |
Overview
- The SDWebImageManager is the class behind the UIImageView+WebCache category and likes.
- It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache).
- You can use this class directly to benefit from web image downloading with caching in another context than
- a UIView. *
- Here is a simple example of how to use SDWebImageManager: *
- @code
SDWebImageManager manager = [SDWebImageManager sharedManager]; [manager downloadWithURL:imageURL options:0 progress:nil completed:^(UIImage image, NSError *error, SDImageCacheType cacheType, BOOL finished) { if (image) { // do something with image } }];
- @endcode
Properties
cacheKeyFilter
- The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
- be used to remove dynamic part of an image URL. *
- The following example sets a filter in the application delegate that will remove any query-string from the
- URL before to use it as a cache key: *
- @code
@property (strong) NSString *^ ) ( NSURL *url ) cacheKeyFilter
Discussion
[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) { url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; return [url absoluteString]; }];
- @endcode
Declared In
SDWebImageManager.h
Instance Methods
diskImageExistsForURL:
Check if image has already been cached
- (BOOL)diskImageExistsForURL:(NSURL *)url
Declared In
SDWebImageManager.h
downloadWithURL:options:progress:completed:
Downloads the image at the given URL if not present in cache or return the cached version otherwise.
- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock
Parameters
- url
The URL to the image
- options
A mask to specify options to use for this request
- progressBlock
A block called while image is downloading
- completedBlock
A block called when operation has been completed.
This parameter is required.
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 an
SDImageCacheType
enum indicating if the image was retrived from the local cache or from the memory cache or from the network.The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is downloading. This block is thus called repetidly with a partial image. When image is fully downloaded, the block is called a last time with the full image and the last parameter set to YES.
Return Value
Returns a cancellable NSOperation
Declared In
SDWebImageManager.h