-
Notifications
You must be signed in to change notification settings - Fork 104
Extending Image Manager Guide
The DFCompositeImageManager
is a dynamic dispatcher that constructs a chain of responsibility from multiple image manager. Each image manager added to the composite defines which image requests it can handle. The DFCompositeImageManager
dispatches image requests starting with the first image manager in a chain. If the image manager can't handle the request it is passes to the next image manager in the chain and so on.
Composite image manager itself conforms to DFImageManagingCore
protocol and can be added to other composite image managers, constructing a tree structure.
DFImageManager
provides a default image manager that contains all built-in fetchers. It's easy to add additional image managers to the default manager "override" existing managers using DFCompositeImageManager
.
Here's an example of how you may add an image manager with a customized DFURLImageFetcher
:
DFURLImageFetcher *URLImageFetcher = /* Create and customize your own URL image fetcher. */
DFImageManager *URLImageManager = [[DFImageManager alloc] initWithConfiguration:[DFImageManagerConfiguration configurationWithFetcher:URLImageFetcher /* Create configuration */ ]];
// Construct a chain of image managers with you manager at the beginning
NSArray *managers = @[ URLImageManager, [DFImageManager sharedManager] ];
[DFImageManager setSharedManager:[[DFCompositeImageManager alloc] initWithImageManagers:managers]];
For more info on customizing DFURLImageFetcher
see documentation. There are ways to customize almost everything.
The DFURLImageFetcher
class is built using Foundation URL Loading System. The URL loading system natively supports the http, https, file, ftp, and data protocols. It also allows clients to extend the number of the supported protocols and to provide their own implementation of natively supported protocols. This functionality is often used by libraries like OHHTTPStubs that are designed to stub network requests for your unit tests.
There are many existing tutorials on the web on how to implement and register your custom URL protocol (subclass of abstract NSURLProtocol
class). There are no other steps required to make those protocols available in DFURLImageFetcher
. However if you are using a DFCompositeImageManager
you should also make sure that the URL scheme supported by your custom protocol is added to the supportedSchemes set of the DFURLImageFetcher
. The set is used when DFURLImageFetcher
determines whether is can handle image request (DFImageRequest
) or not.