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):
localized error: Optional(\"The operation couldn’t be completed. Protocol error\")
error debug description: Optional(Error Domain=NSPOSIXErrorDomain Code=100 \"Protocol error\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>})
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
}
}