Преглед изворни кода

Added back url accepting callback and marked deprecated

Should maintain compatibility with existing implementations while notifying users to change the implementation to the newer `URLResponse` version
Faizan Durrani пре 4 година
родитељ
комит
320d91d24a

+ 1 - 1
Sources/Networking/ImageDownloader.swift

@@ -194,7 +194,7 @@ open class ImageDownloader {
             }
         }
         sessionDelegate.onDidDownloadData.delegate(on: self) { (self, task) in
-            guard let response = task.task.response else {
+            guard task.originalURL != nil, let response = task.task.response else {
                 return task.mutableData
             }
             return (self.delegate ?? self).imageDownloader(self, didDownload: task.mutableData, with: response)

+ 10 - 1
Sources/Networking/ImageDownloaderDelegate.swift

@@ -70,6 +70,9 @@ public protocol ImageDownloaderDelegate: AnyObject {
     ///   `ResponseErrorReason.dataModifyingFailed` will be raised. You could use this fact to stop the image
     ///   processing flow if you find the data is corrupted or malformed.
     func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, with response: URLResponse) -> Data?
+  
+    @available(*, deprecated, message: "use `imageDownloader(_:didDownload:with:)` instead")
+    func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, for url: URL) -> Data?
 
     /// Called when the `ImageDownloader` object successfully downloads and processes an image from specified URL.
     ///
@@ -121,7 +124,13 @@ extension ImageDownloaderDelegate {
     public func isValidStatusCode(_ code: Int, for downloader: ImageDownloader) -> Bool {
         return (200..<400).contains(code)
     }
+  
     public func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, with response: URLResponse) -> Data? {
-        return data
+      guard let url = response.url else { return data }
+      return imageDownloader(downloader, didDownload: data, for: url)
+    }
+  
+    public func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, for url: URL) -> Data? {
+      return data
     }
 }