PINRemoteImageManager Class Reference

Inherits from NSObject
Declared in PINRemoteImageManager.h

Overview

An image downloading, processing and caching manager. It uses the concept of download and processing tasks to ensure that even if multiple calls to download or process an image are made, it only occurs one time (unless an item is no longer in the cache). PINRemoteImageManager is backed by GCD and safe to access from multiple threads simultaneously. It ensures that images are decoded off the main thread so that animation performance isn’t affected. None of its exposed methods allow for synchronous access. However, it is optimized to call completions on the calling thread if an item is in its memory cache. *

– initWithSessionConfiguration:

Create and return a PINRemoteImageManager created with the specified configuration. If configuration is nil, [NSURLSessionConfiguration defaultConfiguration] is used. You specify a custom configuration if you need to configure timeout values, cookie policies, additional HTTP headers, etc.

- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration

Parameters

configuration

The configuration used to create the PINRemoteImageManager.

Return Value

A PINRemoteImageManager with the specified configuration.

Declared In

PINRemoteImageManager.h

+ sharedImageManager

Get the shared instance of PINRemoteImageManager

+ (nonnull instancetype)sharedImageManager

Return Value

Shared instance of PINRemoteImageManager

Declared In

PINRemoteImageManager.h

+ setSharedImageManagerWithConfiguration:

Sets the shared instance of PINRemoteImageManager to an instance with the supplied configuration. If configuration is nil, [NSURLSessionConfiguration defaultConfiguration] is used. You specify a custom configuration if you need to configure timeout values, cookie policies, additional HTTP headers, etc. This method should not be used if the shared instance has already been created.

+ (void)setSharedImageManagerWithConfiguration:(nullable NSURLSessionConfiguration *)configuration

Parameters

configuration

The configuration used to create the PINRemoteImageManager.

Declared In

PINRemoteImageManager.h

– defaultImageCache

The result of this method is assigned to self.cache in init. If you wish to provide a customized cache to the manager you can subclass PINRemoteImageManager and return a custom PINCache from this method.

- (nonnull PINCache *)defaultImageCache

Return Value

An instance of a PINCache object.

Declared In

PINRemoteImageManager.h

– setAuthenticationChallenge:

Set the Authentication Challenge Block.

- (void)setAuthenticationChallenge:(nullable PINRemoteImageManagerAuthenticationChallenge)challengeBlock

Parameters

challengeBlock

A PINRemoteImageManagerAuthenticationChallenge block.

Declared In

PINRemoteImageManager.h

– setHighQualityBPSThreshold:completion:

Set the minimum BPS to download the highest quality image in a set.

- (void)setHighQualityBPSThreshold:(float)highQualityBPSThreshold completion:(nullable dispatch_block_t)completion

Parameters

highQualityBPSThreshold

bytes per second minimum. Defaults to 500000.

completion

Completion to be called once highQualityBPSThreshold has been set.

Declared In

PINRemoteImageManager.h

– setLowQualityBPSThreshold:completion:

Set the maximum BPS to download the lowest quality image in a set.

- (void)setLowQualityBPSThreshold:(float)lowQualityBPSThreshold completion:(nullable dispatch_block_t)completion

Parameters

lowQualityBPSThreshold

bytes per second maximum. Defaults to 50000.

completion

Completion to be called once lowQualityBPSThreshold has been set.

Declared In

PINRemoteImageManager.h

– setShouldUpgradeLowQualityImages:completion:

Set whether high quality images should be downloaded when a low quality image is cached if network connectivity has improved.

- (void)setShouldUpgradeLowQualityImages:(BOOL)shouldUpgradeLowQualityImages completion:(nullable dispatch_block_t)completion

Parameters

shouldUpgradeLowQualityImages

if YES, low quality images will be ‘upgraded’.

completion

Completion to be called once shouldUpgradeLowQualityImages has been set.

Declared In

PINRemoteImageManager.h

– setMaxNumberOfConcurrentOperations:completion:

Set the maximum number of concurrent operations (decompressing images, creating gifs, etc).

- (void)setMaxNumberOfConcurrentOperations:(NSInteger)maxNumberOfConcurrentOperations completion:(nullable dispatch_block_t)completion

Parameters

maxNumberOfConcurrentOperations

The maximum number of concurrent operations. Defaults to NSOperationQueueDefaultMaxConcurrentOperationCount.

completion

Completion to be called once maxNumberOfConcurrentOperations is set.

Declared In

PINRemoteImageManager.h

– setMaxNumberOfConcurrentDownloads:completion:

Set the maximum number of concurrent downloads.

- (void)setMaxNumberOfConcurrentDownloads:(NSInteger)maxNumberOfConcurrentDownloads completion:(nullable dispatch_block_t)completion

Parameters

maxNumberOfConcurrentDownloads

The maximum number of concurrent downloads. Defaults to 10.

completion

Completion to be called once maxNumberOfConcurrentDownloads is set.

Declared In

PINRemoteImageManager.h

– setEstimatedRemainingTimeThresholdForProgressiveDownloads:completion:

Set the estimated time remaining to download threshold at which to generate progressive images. Progressive images previews will only be generated if the estimated remaining time on a download is greater than estimatedTimeRemainingThreshold. If estimatedTimeRemainingThreshold is less than zero, this check is skipped.

- (void)setEstimatedRemainingTimeThresholdForProgressiveDownloads:(NSTimeInterval)estimatedRemainingTimeThreshold completion:(nullable dispatch_block_t)completion

Parameters

estimatedRemainingTimeThreshold

The estimated remaining time threshold used to decide to skip progressive rendering. Defaults to 0.1.

completion

Completion to be called once estimatedTimeRemainingTimeThreshold is set.

Declared In

PINRemoteImageManager.h

– setProgressThresholds:completion:

Sets the progress at which progressive images are generated. By default this is @[@0.00, @0.35, @0.65] which generates at most, 3 progressive images. The first progressive image will only be generated when at least one scan has been completed (so you never see half an image).

- (void)setProgressThresholds:(nonnull NSArray<NSNumber*> *)progressThresholds completion:(nullable dispatch_block_t)completion

Parameters

progressThresholds

an array of progress thresholds at which to generate progressive images. progress thresholds should range from 0.00 - 1.00. Defaults to @[@0.00, @0.35, @0.65]

completion

Completion to be called once progressThresholds is set.

Declared In

PINRemoteImageManager.h

– setProgressiveRendersShouldBlur:completion:

Sets whether PINRemoteImage should blur progressive render results

- (void)setProgressiveRendersShouldBlur:(BOOL)shouldBlur completion:(nullable dispatch_block_t)completion

Parameters

shouldBlur

A bool value indicating whether PINRemoteImage should blur progressive render results

completion

Completion to be called once progressThresholds is set.

Declared In

PINRemoteImageManager.h

– setProgressiveRendersMaxProgressiveRenderSize:completion:

Sets the maximum size of an image that PINRemoteImage will blur. If the image is too large, blurring is skipped

- (void)setProgressiveRendersMaxProgressiveRenderSize:(CGSize)maxProgressiveRenderSize completion:(nullable dispatch_block_t)completion

Parameters

maxProgressiveRenderSize

A CGSize which indicates the max size PINRemoteImage will render a progressive image. If an image is larger in either dimension, progressive rendering will be skipped

completion

Completion to be called once maxProgressiveRenderSize is set.

Declared In

PINRemoteImageManager.h

– prefetchImageWithURL:

Prefetch an image at the given URL.

- (void)prefetchImageWithURL:(nonnull NSURL *)url

Parameters

url

NSURL where the image to prefetch resides.

Declared In

PINRemoteImageManager.h

– prefetchImageWithURL:options:

Prefetch an image at the given URL with given options.

- (void)prefetchImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options

Parameters

url

NSURL where the image to prefetch resides.

options

PINRemoteImageManagerDownloadOptions options with which to pefetch the image.

Declared In

PINRemoteImageManager.h

– prefetchImagesWithURLs:

Prefetch images at the given URLs.

- (void)prefetchImagesWithURLs:(nonnull NSArray<NSURL*> *)urls

Parameters

urls

An array of NSURLs where the images to prefetch reside.

Declared In

PINRemoteImageManager.h

– prefetchImagesWithURLs:options:

Prefetch images at the given URLs with given options.

- (void)prefetchImagesWithURLs:(nonnull NSArray<NSURL*> *)urls options:(PINRemoteImageManagerDownloadOptions)options

Parameters

urls

An array of NSURLs where the images to prefetch reside.

options

PINRemoteImageManagerDownloadOptions options with which to pefetch the image.

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:completion:

Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:options:completion:

Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:options:progressImage:completion:

Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options progressImage:(nullable PINRemoteImageManagerImageCompletion)progressImage completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

progressImage

PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:options:progressDownload:completion:

Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

progressDownload

PINRemoteImageManagerDownloadProgress block which will be called to update progress in bytes of the image download. NOTE: For performance reasons, this block is not called on the main thread every time, if you need to update your UI ensure that you dispatch to the main thread first.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:options:progressImage:progressDownload:completion:

Download or retrieve from cache the image found at the url. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options progressImage:(nullable PINRemoteImageManagerImageCompletion)progressImage progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

progressImage

PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.

progressDownload

PINRemoteImageManagerDownloadProgress block which will be called to update progress in bytes of the image download. NOTE: For performance reasons, this block is not called on the main thread every time, if you need to update your UI ensure that you dispatch to the main thread first.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:options:processorKey:processor:completion:

Download or retrieve from cache the image found at the url and process it before calling completion. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

processorKey

NSString key to uniquely identify processor and process. Will be used for caching processed images.

processor

PINRemoteImageManagerImageProcessor block which will be called to post-process downloaded image.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURL:options:processorKey:processor:progressDownload:completion:

Download or retrieve from cache the image found at the url and process it before calling completion. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURL:(nonnull NSURL *)url options:(PINRemoteImageManagerDownloadOptions)options processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor progressDownload:(nullable PINRemoteImageManagerProgressDownload)progressDownload completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

url

NSURL where the image to download resides.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

processorKey

NSString key to uniquely identify processor and process. Will be used for caching processed images.

processor

PINRemoteImageManagerImageProcessor block which will be called to post-process downloaded image.

progressDownload

PINRemoteImageManagerDownloadProgress block which will be called to update progress in bytes of the image download. NOTE: For performance reasons, this block is not called on the main thread every time, if you need to update your UI ensure that you dispatch to the main thread first.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Declared In

PINRemoteImageManager.h

– downloadImageWithURLs:options:progressImage:completion:

Download or retrieve from cache one of the images found at the urls in the passed in array based on current network performance. URLs should be sorted from lowest quality image URL to highest. All completions are called on an arbitrary callback queue unless called on the main thread and the result is in the memory cache (this is an optimization to allow synchronous results for the UI when an object is cached in memory).

- (nullable NSUUID *)downloadImageWithURLs:(nonnull NSArray<NSURL*> *)urls options:(PINRemoteImageManagerDownloadOptions)options progressImage:(nullable PINRemoteImageManagerImageCompletion)progressImage completion:(nullable PINRemoteImageManagerImageCompletion)completion

Parameters

urls

An array of NSURLs of increasing size.

options

PINRemoteImageManagerDownloadOptions options with which to fetch the image.

progressImage

PINRemoteImageManagerImageCompletion block which will be called to update progress of the image download.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache or downloaded.

Return Value

An NSUUID which uniquely identifies this request. To be used for canceling requests and verifying that the callback is for the request you expect (see categories for example).

Discussion

Unless setShouldUpgradeLowQualityImages is set to YES, this method checks the cache for all URLs and returns the highest quality version stored. It is possible though unlikely for a cached image to not be returned if it is still being cached while a call is made to this method and if network conditions have changed. See source for more details.

Declared In

PINRemoteImageManager.h

– cacheKeyForURL:processorKey:

Returns the cacheKey for a given URL and processorKey. Exposed to be overridden if necessary or to be used with imageFromCacheWithCacheKey

- (nonnull NSString *)cacheKeyForURL:(nonnull NSURL *)url processorKey:(nullable NSString *)processorKey

Parameters

url

NSURL to be downloaded

processorKey

NSString key to uniquely identify processor and process.

Return Value

returns an NSString which is the key used for caching.

Declared In

PINRemoteImageManager.h

– imageFromCacheWithCacheKey:completion:

imageFromCacheWithCacheKey:options:completion: instead @deprecated

- (void)imageFromCacheWithCacheKey:(nonnull NSString *)cacheKey completion:(nonnull PINRemoteImageManagerImageCompletion)completion

Parameters

cacheKey

NSString key to look up image in the cache.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache.

Declared In

PINRemoteImageManager.h

– imageFromCacheWithCacheKey:options:completion:

Directly get an image from the underlying cache.

- (void)imageFromCacheWithCacheKey:(nonnull NSString *)cacheKey options:(PINRemoteImageManagerDownloadOptions)options completion:(nonnull PINRemoteImageManagerImageCompletion)completion

Parameters

cacheKey

NSString key to look up image in the cache.

options

options will be used to determine if the cached image should be decompressed or FLAnimatedImages should be returned.

completion

PINRemoteImageManagerImageCompletion block to call when image has been fetched from the cache.

Declared In

PINRemoteImageManager.h

– synchronousImageFromCacheWithCacheKey:options:

Directly get an image from the underlying memory cache synchronously.

- (nonnull PINRemoteImageManagerResult *)synchronousImageFromCacheWithCacheKey:(nonnull NSString *)cacheKey options:(PINRemoteImageManagerDownloadOptions)options

Parameters

cacheKey

NSString key to look up image in the cache.

options

optoins will be used to determine if the cached image should be decompressed or FLAnimatedImages should be returned.

Return Value

A PINRemoteImageManagerResult

Declared In

PINRemoteImageManager.h

– cancelTaskWithUUID:

Cancel a download. Canceling will only cancel the download if all other downloads are also canceled with their associated UUIDs. Canceling does not guarantee that your completion will not be called. You can use the UUID provided on the result object verify the completion you want called is being called.

- (void)cancelTaskWithUUID:(nonnull NSUUID *)UUID

Parameters

UUID

NSUUID of the task to cancel.

Declared In

PINRemoteImageManager.h

– setPriority:ofTaskWithUUID:

Set the priority of a download task. Since there is only one task per download, the priority of the download task will always be the last priority this method was called with.

- (void)setPriority:(PINRemoteImageManagerPriority)priority ofTaskWithUUID:(nonnull NSUUID *)UUID

Parameters

priority

priority to set on the task.

UUID

NSUUID of the task to set the priority on.

Declared In

PINRemoteImageManager.h

– setProgressImageCallback:ofTaskWithUUID:

set the progress callback on a download task. You can use this to add progress callbacks or remove them for in flight downloads

- (void)setProgressImageCallback:(nullable PINRemoteImageManagerImageCompletion)progressImageCallback ofTaskWithUUID:(nonnull NSUUID *)UUID

Parameters

progressImageCallback

a PINRemoteImageManagerImageCompletion block to be called with a progress update

UUID

NSUUID of the task to set the priority on.

Declared In

PINRemoteImageManager.h