diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 1c008d0..326a452 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 21a3106..1b4beec 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 e7bafc9..7308d2b 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]; }); }