PLXImageManager 4.0.1

PLXImageManager 4.0.1

TestsTested
LangLanguage Obj-CObjective C
License BSD
ReleasedLast Release Jan 2016

Maintained by Antoni Kedracki, Polidea.



  • By
  • Antoni Kedracki

Image manager/downloader for iOS

Usage

Creation

PLXURLImageProvider * provider = [PLXURLImageProvider new];
PLXImageManager * manager = [[PLXImageManager alloc] initWithProvider:provider];

The provider is responsible for retrieving a image if it is not available in cache. The standard PLXURLImageProvider is provided as convenience. It takes a URL and simply downloads up to 5 images at once. By implementing the PLXImageManagerProvider protocol yourself, you can adapt the manager to fit your needs.

Requesting images

[manager imageForIdentifier:@”http://placehold.it/350/00aa00/ffffff” 
                placeholder:[UIImage imageNamed:@”placeholder” 
                   callback:^(UIImage *image, BOOL isPlaceholder) {
    //consume the image here
}];

Canceling requests

The -imageForIdentifier:placeholder:callback: method returns a PLXImageManagerRequestToken that can be used to cancel requests for images.

This is important in scenarios like scrolling a UITableView, when cells can disappear before the download finishes. Canceling those will spare network usage, and reduce the time for the right image to appear.

PLXImageManagerRequestToken * token = nil;

//get token
token = [manager imageForIdentifier:@”http://placehold.it/350/00aa00/ffffff”
                        placeholder:[UIImage imageNamed:@”placeholder”
                           callback:^(UIImage *image, BOOL isPlaceholder) {
    //consume the image here
}];

//cancel the download
[token cancel];

A convenience method is provided to store (and retrieve) a token on any NSObject subclass.

//storing a token
[aObject plx_storeToken:token];

//retrieving a token
token = [aObject plx_retrieveToken];

Caching

PLXImageManager makes use of a combination of memory and file based caches. Refer to the documentation for the memoryCacheCountLimit and fileCacheTotalSizeLimit properties for details.

Example

The included example project demonstrates:

  • instantiating PLXImageManager
  • requesting images using the convenience category on UIImageView

To run it, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 7+

Installation

PLXImageManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PLXImageManager"

Author

Antoni Kedracki, [email protected]

You can read more about the internal workings of PLImageManager here.

License

PLXImageManager is available under the BSD license. See the LICENSE file for more info.

Copyright (c) 2013 Polidea. This software is licensed under the BSD License.