From 49acbdf9a97f9c6f1c92cba2577eae82d73bc0e4 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 27 Feb 2018 23:12:06 +0800 Subject: [PATCH 1/2] Fix that iOS 8 NSURLSessionTaskPriorityHigh symbol not defined in Foundation framework and cause crash --- SDWebImage/SDWebImageDownloaderOperation.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 99e508ae..722645f0 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -14,6 +14,13 @@ #define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER); #define UNLOCK(lock) dispatch_semaphore_signal(lock); +// iOS 8 Foundation.framework extern these symbol but the define is in CFNetwork.framework. We just fix this without import CFNetwork.framework +#if (__IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0) +const float NSURLSessionTaskPriorityHigh = 0.75; +const float NSURLSessionTaskPriorityDefault = 0.5; +const float NSURLSessionTaskPriorityLow = 0.25; +#endif + NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification"; NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; @@ -176,7 +183,6 @@ typedef NSMutableDictionary SDCallbacksDictionary; } if (self.dataTask) { - [self.dataTask resume]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability" if ([self.dataTask respondsToSelector:@selector(setPriority:)]) { @@ -187,6 +193,7 @@ typedef NSMutableDictionary SDCallbacksDictionary; } } #pragma clang diagnostic pop + [self.dataTask resume]; for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) { progressBlock(0, NSURLResponseUnknownLength, self.request.URL); } From a2eb8958aba4e51992469f704e419fd2b22fe29b Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 28 Feb 2018 00:04:56 +0800 Subject: [PATCH 2/2] Update the comments --- SDWebImage/SDWebImageDownloader.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index 54224c5c..b5911aff 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -11,7 +11,14 @@ #import "SDWebImageOperation.h" typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { + /** + * Put the download in the low queue priority and task priority. + */ SDWebImageDownloaderLowPriority = 1 << 0, + + /** + * This flag enables progressive download, the image is displayed progressively during download as a browser would do. + */ SDWebImageDownloaderProgressiveDownload = 1 << 1, /** @@ -45,7 +52,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, /** - * Put the image in the high priority queue. + * Put the download in the high queue priority and task priority. */ SDWebImageDownloaderHighPriority = 1 << 7,