Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add new method to SDWebImagePrefetcher to support a completion block #127

Closed
wants to merge 1 commit into from

2 participants

Scott Lemke Olivier Poitrey
Scott Lemke

Patch for Issue #126

Olivier Poitrey rs closed this in 350c0be
Martín Conte Mac Donell Reflejo referenced this pull request from a commit in Kicksend/SDWebImage
Martín Conte Mac Donell Reflejo Merge remote-tracking branch 'upstream/master'
* upstream/master:
  Prefetching file properties in the disk cleaning enumerator
  correct cachePolicy constants.
  Add (kinda) LIFO queue mode support for image downloading (fix #294)
  Add completion block support to `SDWebImagePrefetcher` (fix #127)
  Add `SDWebImageManager` delegate allowing fine control of manager's cache-in
  Add ability to set custom downloader HTTP headers (fix #171)
  Synchronize access to SDWebImageManager's mutable structures (fix #301)
  [BUG] Fix invalid alpha on JPEG files
f62788f
Martín Conte Mac Donell Reflejo referenced this pull request from a commit in Kicksend/SDWebImage
Martín Conte Mac Donell Reflejo Merge remote-tracking branch 'upstream/master'
* upstream/master:
  Detect parent operation cancellation in download operation completion block
  Prefetching file properties in the disk cleaning enumerator
  correct cachePolicy constants.
  Add (kinda) LIFO queue mode support for image downloading (fix #294)
  Add completion block support to `SDWebImagePrefetcher` (fix #127)
  Add `SDWebImageManager` delegate allowing fine control of manager's cache-in
  Add ability to set custom downloader HTTP headers (fix #171)
  Synchronize access to SDWebImageManager's mutable structures (fix #301)
  [BUG] Fix invalid alpha on JPEG files
1f88283
山楂片 hawflakes referenced this pull request from a commit in hawflakes/SDWebImage
Olivier Poitrey Add completion block support to `SDWebImagePrefetcher` (fix #127) 9628a7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
8 SDWebImage/SDWebImagePrefetcher.h
View
@@ -10,6 +10,10 @@
#import "SDWebImageManagerDelegate.h"
#import "SDWebImageManager.h"
+#if NS_BLOCKS_AVAILABLE
+typedef void (^SDWebImagePrefetcherCompletion)(NSUInteger finishedCount, NSUInteger skippedCount);
+#endif
+
/**
* Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
*/
@@ -46,7 +50,9 @@
* @param urls list of URLs to prefetch
*/
- (void)prefetchURLs:(NSArray *)urls;
-
+#if NS_BLOCKS_AVAILABLE
+- (void)prefetchURLs:(NSArray *)urls completion:(SDWebImagePrefetcherCompletion)completion;
+#endif
/**
* Remove and cancel queued list
35 SDWebImage/SDWebImagePrefetcher.m
View
@@ -10,7 +10,15 @@
#import "SDWebImageManager.h"
@interface SDWebImagePrefetcher ()
+{
+#if NS_BLOCKS_AVAILABLE
+ SDWebImagePrefetcherCompletion _completion;
+#endif
+}
@property (nonatomic, retain) NSArray *prefetchURLs;
+#if NS_BLOCKS_AVAILABLE
+@property (nonatomic, copy) SDWebImagePrefetcherCompletion completion;
+#endif
@end
@implementation SDWebImagePrefetcher
@@ -20,6 +28,9 @@ @implementation SDWebImagePrefetcher
@synthesize prefetchURLs;
@synthesize maxConcurrentDownloads;
@synthesize options;
+#if NS_BLOCKS_AVAILABLE
+@synthesize completion = _completion;
+#endif
+ (SDWebImagePrefetcher *)sharedImagePrefetcher
{
@@ -61,6 +72,15 @@ - (void)prefetchURLs:(NSArray *)urls
}
}
+#if NS_BLOCKS_AVAILABLE
+- (void)prefetchURLs:(NSArray *)urls completion:(SDWebImagePrefetcherCompletion)completion
+{
+ self.completion = completion;
+ [self prefetchURLs:urls];
+}
+#endif
+
+
- (void)cancelPrefetching
{
self.prefetchURLs = nil;
@@ -84,6 +104,12 @@ - (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UI
else if (_finishedCount == _requestedCount)
{
[self reportStatus];
+#if NS_BLOCKS_AVAILABLE
+ if(self.completion != nil) {
+ self.completion(_finishedCount, _skippedCount);
+ self.completion = nil;
+ }
+#endif
}
}
@@ -102,12 +128,21 @@ - (void)webImageManager:(SDWebImageManager *)imageManager didFailWithError:(NSEr
else if (_finishedCount == _requestedCount)
{
[self reportStatus];
+#if NS_BLOCKS_AVAILABLE
+ if(self.completion != nil) {
+ self.completion(_finishedCount, _skippedCount);
+ self.completion = nil;
+ }
+#endif
}
}
- (void)dealloc
{
self.prefetchURLs = nil;
+#if NS_BLOCKS_AVAILABLE
+ self.completion = nil;
+#endif
SDWISuperDealoc;
}
Something went wrong with that request. Please try again.