URLSessionDownloadTask doesn't resume on fail

740 views Asked by At

URLSessionDownload Task works well for video download but some Authenticated Vimeo URLs for HQ videos(large data) generates following error with no resume data.

So how do I resume download ???

I am getting error while downloading video task fails (different logs of error are):

  1. localized error: Optional(\"The operation couldn’t be completed. Protocol error\")

  2. error debug description: Optional(Error Domain=NSPOSIXErrorDomain Code=100 \"Protocol error\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>})

  3. error unsafelyUnwrapped :Error Domain=NSPOSIXErrorDomain Code=100 \"Protocol error\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>}"

//Code

var downloadTask: URLSessionDownloadTask?
var SessionRequest : URLRequest?

let backgroundSessionConfiguration = URLSessionConfiguration.background(withIdentifier: "\(Bundle.main.bundleIdentifier!).background")

let url = URL(string: urlString)!
SessionRequest = URLRequest(url: url)
SessionRequest?.httpMethod = "GET"
downloadTask = backgroundSession.downloadTask(with: SessionRequest!)
downloadTask?.resume()

//Delegate called sometimes when resulting into error with no RESUME DATA

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {


        if error != nil {
            debugPrint("Task completed: \(String(describing: task)),localized error: \(String(describing: error?.localizedDescription)) error debug desc: \(String(describing: error.debugDescription)) error unsafelyUnwrapped :\(error.unsafelyUnwrapped)")

        let err = error! as NSError
        let data = (err.userInfo)[NSURLSessionDownloadTaskResumeData]
         //Above data is always nil so cannot resume
        }
}
0

There are 0 answers