|
@@ -20,6 +20,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -20,6 +20,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
20
|
|
20
|
|
21
|
@property (strong, nonatomic) NSOperationQueue *downloadQueue;
|
21
|
@property (strong, nonatomic) NSOperationQueue *downloadQueue;
|
22
|
@property (weak, nonatomic) NSOperation *lastAddedOperation;
|
22
|
@property (weak, nonatomic) NSOperation *lastAddedOperation;
|
|
|
23
|
+@property (assign, nonatomic) Class operationClass;
|
23
|
@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
|
24
|
@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
|
24
|
@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
|
25
|
@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
|
25
|
// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
|
26
|
// 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"; |
|
@@ -63,6 +64,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
63
|
|
64
|
|
64
|
- (id)init {
|
65
|
- (id)init {
|
65
|
if ((self = [super init])) {
|
66
|
if ((self = [super init])) {
|
|
|
67
|
+ _operationClass = [SDWebImageDownloaderOperation class];
|
66
|
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
68
|
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
67
|
_downloadQueue = [NSOperationQueue new];
|
69
|
_downloadQueue = [NSOperationQueue new];
|
68
|
_downloadQueue.maxConcurrentOperationCount = 2;
|
70
|
_downloadQueue.maxConcurrentOperationCount = 2;
|
|
@@ -104,6 +106,10 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -104,6 +106,10 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
104
|
return _downloadQueue.maxConcurrentOperationCount;
|
106
|
return _downloadQueue.maxConcurrentOperationCount;
|
105
|
}
|
107
|
}
|
106
|
|
108
|
|
|
|
109
|
+- (void)setOperationClass:(Class)operationClass {
|
|
|
110
|
+ _operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
|
|
|
111
|
+}
|
|
|
112
|
+
|
107
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
113
|
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
108
|
__block SDWebImageDownloaderOperation *operation;
|
114
|
__block SDWebImageDownloaderOperation *operation;
|
109
|
__weak SDWebImageDownloader *wself = self;
|
115
|
__weak SDWebImageDownloader *wself = self;
|
|
@@ -124,7 +130,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
|
@@ -124,7 +130,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; |
124
|
else {
|
130
|
else {
|
125
|
request.allHTTPHeaderFields = wself.HTTPHeaders;
|
131
|
request.allHTTPHeaderFields = wself.HTTPHeaders;
|
126
|
}
|
132
|
}
|
127
|
- operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
|
133
|
+ operation = [[wself.operationClass alloc] initWithRequest:request
|
128
|
options:options
|
134
|
options:options
|
129
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
135
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
130
|
SDWebImageDownloader *sself = wself;
|
136
|
SDWebImageDownloader *sself = wself;
|