Adds setter to override default SDWebImageDownloaderOperation.
This commit is contained in:
parent
6dfec7ccd9
commit
3671cdde0f
|
@ -139,6 +139,16 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
|
|||
*/
|
||||
- (NSString *)valueForHTTPHeaderField:(NSString *)field;
|
||||
|
||||
/**
|
||||
* Sets a subclass of `SDWebImageDownloaderOperation` as the default
|
||||
* `NSOperation` to be used each time SDWebImage constructs a request
|
||||
* operation to download an image.
|
||||
*
|
||||
* @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
|
||||
* as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
|
||||
*/
|
||||
- (void)setOperationClass:(Class)operationClass;
|
||||
|
||||
/**
|
||||
* Creates a SDWebImageDownloader async downloader instance with a given URL
|
||||
*
|
||||
|
|
|
@ -20,6 +20,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
|
||||
@property (strong, nonatomic) NSOperationQueue *downloadQueue;
|
||||
@property (weak, nonatomic) NSOperation *lastAddedOperation;
|
||||
@property (assign, nonatomic) Class operationClass;
|
||||
@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
|
||||
@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
|
||||
// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
|
||||
|
@ -63,6 +64,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
|
||||
- (id)init {
|
||||
if ((self = [super init])) {
|
||||
_operationClass = [SDWebImageDownloaderOperation class];
|
||||
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
||||
_downloadQueue = [NSOperationQueue new];
|
||||
_downloadQueue.maxConcurrentOperationCount = 2;
|
||||
|
@ -104,6 +106,10 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
return _downloadQueue.maxConcurrentOperationCount;
|
||||
}
|
||||
|
||||
- (void)setOperationClass:(Class)operationClass {
|
||||
_operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
|
||||
}
|
||||
|
||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||
__block SDWebImageDownloaderOperation *operation;
|
||||
__weak SDWebImageDownloader *wself = self;
|
||||
|
@ -124,7 +130,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
else {
|
||||
request.allHTTPHeaderFields = wself.HTTPHeaders;
|
||||
}
|
||||
operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
|
||||
operation = [[wself.operationClass alloc] initWithRequest:request
|
||||
options:options
|
||||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||
SDWebImageDownloader *sself = wself;
|
||||
|
|
Loading…
Reference in New Issue