Kaynağa Gözat

Merge branch 'master' of https://github.com/rs/SDWebImage into 5.x

* 'master' of https://github.com/rs/SDWebImage:
  Bumped version to 4.3.2
  Follow Apple's doc, add NSOperation only after all configuration done.
  Update the comments
  Fix that iOS 8 NSURLSessionTaskPriorityHigh symbol not defined in Foundation framework and cause crash
DreamPiggy 8 yıl önce
ebeveyn
işleme
3ba2fd8e6a

+ 12 - 1
CHANGELOG.md

@@ -1,4 +1,15 @@
-## [4.3.1 - 4.3.0 Patch](https://github.com/rs/SDWebImage/releases/tag/4.3.1)
+## [4.3.2 - 4.3 Patch, on Feb 28th, 2018](https://github.com/rs/SDWebImage/releases/tag/4.3.2)
+See [all tickets marked for the 4.3.2 release](https://github.com/rs/SDWebImage/milestone/23)
+
+#### Fixes
+- Download Operation
+	- Fix that iOS 8 NSURLSessionTaskPriorityHigh symbol not defined in Foundation framework and cause crash #2231 #2230
+
+#### Improvements
+- Downloader
+	- Follow Apple's doc, add NSOperation only after all configuration done #2232
+
+## [4.3.1 - 4.3 Patch, on Feb 25th, 2018](https://github.com/rs/SDWebImage/releases/tag/4.3.1)
 See [all tickets marked for the 4.3.1 release](https://github.com/rs/SDWebImage/milestone/22)
 
 #### Fixes

+ 1 - 1
SDWebImage.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
   s.name = 'SDWebImage'
-  s.version = '4.3.1'
+  s.version = '4.3.2'
 
   s.osx.deployment_target = '10.10'
   s.ios.deployment_target = '8.0'

+ 8 - 1
SDWebImage/SDWebImageDownloader.h

@@ -12,7 +12,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,
 
     /**
@@ -46,7 +53,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,
     

+ 4 - 2
SDWebImage/SDWebImageDownloader.m

@@ -239,8 +239,7 @@
         } else if (options & SDWebImageDownloaderLowPriority) {
             operation.queuePriority = NSOperationQueuePriorityLow;
         }
-
-        [sself.downloadQueue addOperation:operation];
+        
         if (sself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
             // Emulate LIFO execution order by systematically adding new operations as last operation's dependency
             [sself.lastAddedOperation addDependency:operation];
@@ -294,6 +293,9 @@
             UNLOCK(sself.operationsLock);
         };
         [self.URLOperations setObject:operation forKey:url];
+        // Add operation to operation queue only after all configuration done according to Apple's doc.
+        // `addOperation:` does not synchronously execute the `operation.completionBlock` so this will not cause deadlock.
+        [self.downloadQueue addOperation:operation];
     }
     UNLOCK(self.operationsLock);
 

+ 8 - 1
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";
@@ -187,7 +194,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
     }
 
     if (self.dataTask) {
-        [self.dataTask resume];
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunguarded-availability"
         if ([self.dataTask respondsToSelector:@selector(setPriority:)]) {
@@ -198,6 +204,7 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
             }
         }
 #pragma clang diagnostic pop
+        [self.dataTask resume];
         for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
             progressBlock(0, NSURLResponseUnknownLength, self.request.URL);
         }

+ 2 - 2
WebImage/Info.plist

@@ -15,11 +15,11 @@
 	<key>CFBundlePackageType</key>
 	<string>FMWK</string>
 	<key>CFBundleShortVersionString</key>
-	<string>4.3.1</string>
+	<string>4.3.2</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>4.3.1</string>
+	<string>4.3.2</string>
 	<key>NSPrincipalClass</key>
 	<string></string>
 </dict>