From 056e1e65620b6dfc633977ab12a92515f16a5fcd Mon Sep 17 00:00:00 2001 From: Fabrice Aneche Date: Mon, 6 Jan 2014 16:14:32 -0800 Subject: [PATCH 1/2] use a NSInteger as size (cause we are using -1 as start indicator) --- SDWebImage/SDWebImageDownloader.h | 2 +- SDWebImage/SDWebImageDownloader.m | 6 +++--- SDWebImage/SDWebImageDownloaderOperation.m | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index adb24cb1..d9dd3dee 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -57,7 +57,7 @@ typedef enum extern NSString *const SDWebImageDownloadStartNotification; extern NSString *const SDWebImageDownloadStopNotification; -typedef void(^SDWebImageDownloaderProgressBlock)(NSUInteger receivedSize, NSUInteger expectedSize); +typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); /** diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 6f8ab90a..a6e6ed8a 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -115,7 +115,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; return _downloadQueue.maxConcurrentOperationCount; } -- (id)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock +- (id)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSInteger, NSInteger))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock { __block SDWebImageDownloaderOperation *operation; __weak SDWebImageDownloader *wself = self; @@ -139,7 +139,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; { request.allHTTPHeaderFields = wself.HTTPHeaders; } - operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSUInteger receivedSize, NSUInteger expectedSize) + operation = [SDWebImageDownloaderOperation.alloc initWithRequest:request options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { if (!wself) return; SDWebImageDownloader *sself = wself; @@ -183,7 +183,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; return operation; } -- (void)addProgressCallback:(void (^)(NSUInteger, NSUInteger))progressBlock andCompletedBlock:(void (^)(UIImage *, NSData *data, NSError *, BOOL))completedBlock forURL:(NSURL *)url createCallback:(void (^)())createCallback +- (void)addProgressCallback:(void (^)(NSInteger, NSInteger))progressBlock andCompletedBlock:(void (^)(UIImage *, NSData *data, NSError *, BOOL))completedBlock forURL:(NSURL *)url createCallback:(void (^)())createCallback { // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. if(url == nil) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 38d77026..1aed4b38 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -19,7 +19,7 @@ @property (assign, nonatomic, getter = isExecuting) BOOL executing; @property (assign, nonatomic, getter = isFinished) BOOL finished; -@property (assign, nonatomic) NSUInteger expectedSize; +@property (assign, nonatomic) NSInteger expectedSize; @property (strong, nonatomic) NSMutableData *imageData; @property (strong, nonatomic) NSURLConnection *connection; @property (strong, atomic) NSThread *thread; @@ -36,7 +36,7 @@ BOOL responseFromCached; } -- (id)initWithRequest:(NSURLRequest *)request options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock cancelled:(void (^)())cancelBlock +- (id)initWithRequest:(NSURLRequest *)request options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSInteger, NSInteger))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock cancelled:(void (^)())cancelBlock { if ((self = [super init])) { @@ -208,7 +208,7 @@ { if (![response respondsToSelector:@selector(statusCode)] || [((NSHTTPURLResponse *)response) statusCode] < 400) { - NSUInteger expected = response.expectedContentLength > 0 ? (NSUInteger)response.expectedContentLength : 0; + NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0; self.expectedSize = expected; if (self.progressBlock) { @@ -242,7 +242,7 @@ // Thanks to the author @Nyx0uf // Get the total bytes downloaded - const NSUInteger totalSize = self.imageData.length; + const NSInteger totalSize = self.imageData.length; // Update the data source, we must pass ALL the data, not just the new bytes CGImageSourceRef imageSource = CGImageSourceCreateIncremental(NULL); From 765a89712062c62c759e0931a2e9c977ed912588 Mon Sep 17 00:00:00 2001 From: Fabrice Aneche Date: Mon, 6 Jan 2014 16:22:07 -0800 Subject: [PATCH 2/2] more details about delegate call with -1 NSURLResponseUnknownLength --- SDWebImage/SDWebImageDownloaderOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 1aed4b38..e886fb5c 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -94,7 +94,7 @@ { if (self.progressBlock) { - self.progressBlock(0, -1); + self.progressBlock(0, NSURLResponseUnknownLength); } [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];