Authored by DreamPiggy
Committed by GitHub

Merge pull request #2231 from dreampiggy/fix_iOS8_priority_symbol_crash

Fix that iOS 8 NSURLSessionTaskPriorityHigh symbol not defined in Foundation framework and cause crash
@@ -11,7 +11,14 @@ @@ -11,7 +11,14 @@
11 #import "SDWebImageOperation.h" 11 #import "SDWebImageOperation.h"
12 12
13 typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { 13 typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
  14 + /**
  15 + * Put the download in the low queue priority and task priority.
  16 + */
14 SDWebImageDownloaderLowPriority = 1 << 0, 17 SDWebImageDownloaderLowPriority = 1 << 0,
  18 +
  19 + /**
  20 + * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
  21 + */
15 SDWebImageDownloaderProgressiveDownload = 1 << 1, 22 SDWebImageDownloaderProgressiveDownload = 1 << 1,
16 23
17 /** 24 /**
@@ -45,7 +52,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { @@ -45,7 +52,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
45 SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, 52 SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
46 53
47 /** 54 /**
48 - * Put the image in the high priority queue. 55 + * Put the download in the high queue priority and task priority.
49 */ 56 */
50 SDWebImageDownloaderHighPriority = 1 << 7, 57 SDWebImageDownloaderHighPriority = 1 << 7,
51 58
@@ -14,6 +14,13 @@ @@ -14,6 +14,13 @@
14 #define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER); 14 #define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
15 #define UNLOCK(lock) dispatch_semaphore_signal(lock); 15 #define UNLOCK(lock) dispatch_semaphore_signal(lock);
16 16
  17 +// iOS 8 Foundation.framework extern these symbol but the define is in CFNetwork.framework. We just fix this without import CFNetwork.framework
  18 +#if (__IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
  19 +const float NSURLSessionTaskPriorityHigh = 0.75;
  20 +const float NSURLSessionTaskPriorityDefault = 0.5;
  21 +const float NSURLSessionTaskPriorityLow = 0.25;
  22 +#endif
  23 +
17 NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; 24 NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification";
18 NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification"; 25 NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification";
19 NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; 26 NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
@@ -176,7 +183,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; @@ -176,7 +183,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
176 } 183 }
177 184
178 if (self.dataTask) { 185 if (self.dataTask) {
179 - [self.dataTask resume];  
180 #pragma clang diagnostic push 186 #pragma clang diagnostic push
181 #pragma clang diagnostic ignored "-Wunguarded-availability" 187 #pragma clang diagnostic ignored "-Wunguarded-availability"
182 if ([self.dataTask respondsToSelector:@selector(setPriority:)]) { 188 if ([self.dataTask respondsToSelector:@selector(setPriority:)]) {
@@ -187,6 +193,7 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; @@ -187,6 +193,7 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
187 } 193 }
188 } 194 }
189 #pragma clang diagnostic pop 195 #pragma clang diagnostic pop
  196 + [self.dataTask resume];
190 for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) { 197 for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
191 progressBlock(0, NSURLResponseUnknownLength, self.request.URL); 198 progressBlock(0, NSURLResponseUnknownLength, self.request.URL);
192 } 199 }