Asynchronous image downloader with cache support
It provides:
- An asynchronous image downloader
- An asynchronous disk image caching with automatic cache expiration handling
- Resuming interrupted downloads
- Multi-Threaded downloading
- Tracking download progress
- LRU cache cleanup
- Use GCD and ARC
NOTE: Requires iOS 5.0
With blocks, you can be notified about the image download progress and whenever the image retrival has completed with success or not:
#import "OLImageDownloader.h"
@interface ActivityVideoCell ()
@property (nonatomic, strong) UIImage *avatarImage;
@property (nonatomic, strong) OLImageOperationHandler *avatarImageOperation;
@end
- (void)downloadAvatarImage {
if (!_avatarImageOperation) {
NSURL *imageUrl = [NSURL URLWithString:self.layout.activity.user.avatarUrl];
OLImageDownloader *downloader = [OLImageDownloader shared];
_avatarImageOperation = [downloader downloadImageWithURL:imageUrl
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
{
if (image)
{
self.avatarImage = image;
[self setNeedsDisplay];
}
if (finished) {
_avatarImageOperation = nil;
}
}];
}
}
Note: neither your success nor failure block will be call if your image request is canceled before completion.
It's easy to use this in your project, just copy all the files into your project.
- In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block:
- Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature:
In the source files where you need to use the library, import the header file:
#import "OLImageDownloader.h"
All source code is licensed under the MIT License.