iOS prefetch images

August 12, 2015

iOS prefetch images

iOS prefetch images procedure is quite simple with SDWebImage library, which you can download here.

After you have imported header file SDWebImagePrefetcher.h, all you need to do is to write a single line of code:

[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:mediaURLs];

In case you want to show UIProgressView with the current progress, you could use this method:

__weak typeof(self)weakSelf = self;
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:mediaURLs progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf.progressView setProgress:progress animated:YES];
    } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf.alert dismissWithClickedButtonIndex:0 animated:YES];
    }];

Comments

comments powered by Disqus