From cd977d70a49cd2035d2bed38590bffd098cce5d1 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Tue, 16 Dec 2014 11:48:26 +0900 Subject: [PATCH 1/4] Improve operation behavior to get more information of it. --- SDWebImage/SDWebImageDownloader.m | 3 --- SDWebImage/SDWebImageDownloaderOperation.h | 15 +++++++++++++++ SDWebImage/SDWebImageDownloaderOperation.m | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 1c008d0c..326a452a 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -10,9 +10,6 @@ #import "SDWebImageDownloaderOperation.h" #import -NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; -NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; - static NSString *const kProgressCallbackKey = @"progress"; static NSString *const kCompletedCallbackKey = @"completed"; diff --git a/SDWebImage/SDWebImageDownloaderOperation.h b/SDWebImage/SDWebImageDownloaderOperation.h index 21a3106a..1b4beece 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.h +++ b/SDWebImage/SDWebImageDownloaderOperation.h @@ -10,6 +10,11 @@ #import "SDWebImageDownloader.h" #import "SDWebImageOperation.h" +extern NSString *const SDWebImageDownloadStartNotification; +extern NSString *const SDWebImageDownloadReceiveResponseNotification; +extern NSString *const SDWebImageDownloadStopNotification; +extern NSString *const SDWebImageDownloadFinishNotification; + @interface SDWebImageDownloaderOperation : NSOperation /** @@ -36,6 +41,16 @@ */ @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options; +/** + * The expected size of data. + */ +@property (assign, nonatomic) NSInteger expectedSize; + +/** + * The response returned by the operation's connection. + */ +@property (strong, nonatomic) NSURLResponse *response; + /** * Initializes a `SDWebImageDownloaderOperation` object * diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index e7bafc96..7308d2b9 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -12,6 +12,11 @@ #import #import "SDWebImageManager.h" +NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; +NSString *const SDWebImageDownloadReseiveResponseNotification = @"SDWebImageDownloadReseiveResponseNotification"; +NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; +NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification"; + @interface SDWebImageDownloaderOperation () @property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock; @@ -20,7 +25,6 @@ @property (assign, nonatomic, getter = isExecuting) BOOL executing; @property (assign, nonatomic, getter = isFinished) BOOL finished; -@property (assign, nonatomic) NSInteger expectedSize; @property (strong, nonatomic) NSMutableData *imageData; @property (strong, nonatomic) NSURLConnection *connection; @property (strong, atomic) NSThread *thread; @@ -209,6 +213,10 @@ } self.imageData = [[NSMutableData alloc] initWithCapacity:expected]; + self.response = response; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadResponseNotification object:self]; + }); } else { NSUInteger code = [((NSHTTPURLResponse *)response) statusCode]; @@ -221,7 +229,7 @@ [self.connection cancel]; } dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; }); if (self.completedBlock) { @@ -346,7 +354,8 @@ self.thread = nil; self.connection = nil; dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self]; }); } @@ -385,7 +394,7 @@ self.thread = nil; self.connection = nil; dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; }); } From 327c444322e1ce618fb4f7797e70903ef200a271 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Tue, 16 Dec 2014 12:23:41 +0900 Subject: [PATCH 2/4] Fix notification name. --- SDWebImage/SDWebImageDownloaderOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 7308d2b9..3d7d7691 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -215,7 +215,7 @@ NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinis self.imageData = [[NSMutableData alloc] initWithCapacity:expected]; self.response = response; dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadResponseNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self]; }); } else { From d90d1158931452b51231a1ab1be07ab1a028ee4d Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Tue, 16 Dec 2014 12:24:57 +0900 Subject: [PATCH 3/4] Fix notification name. --- SDWebImage/SDWebImageDownloaderOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 7308d2b9..3d7d7691 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -215,7 +215,7 @@ NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinis self.imageData = [[NSMutableData alloc] initWithCapacity:expected]; self.response = response; dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadResponseNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self]; }); } else { From f7a2321107bb7582894e5527133818413cd04db8 Mon Sep 17 00:00:00 2001 From: Naoki Morita Date: Tue, 16 Dec 2014 12:35:17 +0900 Subject: [PATCH 4/4] Fix typo. --- SDWebImage/SDWebImageDownloaderOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 3d7d7691..3509dd13 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -13,7 +13,7 @@ #import "SDWebImageManager.h" NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; -NSString *const SDWebImageDownloadReseiveResponseNotification = @"SDWebImageDownloadReseiveResponseNotification"; +NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification"; NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification";