Inherits from NSObject
Declared in SDWebImageManager.h

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 downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage image, NSError error, SDImageCacheType cacheType, BOOL finished, NSURL imageURL) { if (image) { // do something with image } }];

  • @endcode

Tasks

Other Methods

Deprecated Methods

  • – downloadWithURL:options:progress:completed:

    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:)

Properties

cacheKeyFilter

@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter
Discussion
  • 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

[[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

delegate

@property (weak, nonatomic) id<SDWebImageManagerDelegate> delegate

imageCache

@property (strong, nonatomic, readonly) SDImageCache *imageCache

imageDownloader

@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader

Class Methods

sharedManager

+ (SDWebImageManager *)sharedManager
Discussion

Returns global SDWebImageManager instance.

Return Value

SDWebImageManager shared instance

Declared In

SDWebImageManager.h

Instance Methods

cacheKeyForURL:

- (NSString *)cacheKeyForURL:(NSURL *)url
Discussion

Return the cache key for a given URL

Declared In

SDWebImageManager.h

cachedImageExistsForURL:

- (BOOL)cachedImageExistsForURL:(NSURL *)url
Discussion

Check if image has already been cached

Parameters

url

image url

Return Value

if the image was already cached

Declared In

SDWebImageManager.h

cachedImageExistsForURL:completion:

- (void)cachedImageExistsForURL:(NSURL *)url completion:(SDWebImageCheckCacheCompletionBlock)completionBlock
Discussion

Async check if image has already been cached

Note: the completion block is always executed on the main queue

Parameters

url

image url

completionBlock

the block to be executed when the check is finished

Declared In

SDWebImageManager.h

cancelAll

- (void)cancelAll
Discussion

Cancel all current opreations

Declared In

SDWebImageManager.h

diskImageExistsForURL:

- (BOOL)diskImageExistsForURL:(NSURL *)url
Discussion

Check if image has already been cached on disk only

Parameters

url

image url

Return Value

if the image was already cached (disk only)

Declared In

SDWebImageManager.h

diskImageExistsForURL:completion:

- (void)diskImageExistsForURL:(NSURL *)url completion:(SDWebImageCheckCacheCompletionBlock)completionBlock
Discussion

Async check if image has already been cached on disk only

Note: the completion block is always executed on the main queue

Parameters

url

image url

completionBlock

the block to be executed when the check is finished

Declared In

SDWebImageManager.h

downloadImageWithURL:options:progress:completed:

- (id<SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionWithFinishedBlock)completedBlock
Discussion

Downloads the image at the given URL if not present in cache or return the cached version otherwise.

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 an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation

Declared In

SDWebImageManager.h

downloadWithURL:options:progress:completed:

- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock
Discussion

Downloads the image at the given URL if not present in cache or return the cached version otherwise.

Declared In

SDWebImageManager.h

isRunning

- (BOOL)isRunning
Discussion

Check one or more operations running

Declared In

SDWebImageManager.h

saveImageToCache:forURL:

- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url
Discussion

Saves image to cache for given URL

Parameters

image

The image to cache

url

The URL to the image

Declared In

SDWebImageManager.h