Browse Source

Failed download task delegate now stores resume data if it is available.

Christian Noon 10 years ago
parent
commit
74ac42c9fa
2 changed files with 10 additions and 2 deletions
  1. 1 1
      Source/Download.swift
  2. 9 1
      Source/Request.swift

+ 1 - 1
Source/Download.swift

@@ -141,7 +141,7 @@ extension Request {
         var downloadProgress: ((Int64, Int64, Int64) -> Void)?
         var downloadProgress: ((Int64, Int64, Int64) -> Void)?
 
 
         var resumeData: NSData?
         var resumeData: NSData?
-        override var data: NSData? { return resumeData }
+        override var data: NSData? { return self.resumeData }
 
 
         // MARK: - NSURLSessionDownloadDelegate
         // MARK: - NSURLSessionDownloadDelegate
 
 

+ 9 - 1
Source/Request.swift

@@ -305,8 +305,16 @@ public class Request {
             if let taskDidCompleteWithError = self.taskDidCompleteWithError {
             if let taskDidCompleteWithError = self.taskDidCompleteWithError {
                 taskDidCompleteWithError(session, task, error)
                 taskDidCompleteWithError(session, task, error)
             } else {
             } else {
-                if error != nil {
+                if let error = error {
                     self.error = error
                     self.error = error
+
+                    if let
+                        downloadDelegate = self as? DownloadTaskDelegate,
+                        userInfo = error.userInfo as? [String: AnyObject],
+                        resumeData = userInfo[NSURLSessionDownloadTaskResumeData] as? NSData
+                    {
+                        downloadDelegate.resumeData = resumeData
+                    }
                 }
                 }
 
 
                 self.queue.suspended = false
                 self.queue.suspended = false