URLSessionDownload 任务适用于视频下载,但总部视频(大数据)的一些经过身份验证的 Vimeo URL 会生成以下错误,但没有恢复数据。
那么如何恢复下载???
下载视频任务失败时出现错误(不同的错误日志是):
本地化错误:可选(\“操作无法完成。协议错误\”)
错误调试描述:可选(错误域=NSPOSIXErrorDomain Code=100 \"Protocol error\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>})
错误 unsafelyUnwrapped :Error Domain=NSPOSIXErrorDomain Code=100 \"协议错误\" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=100, NSErrorPeerAddressKey=<100201bb 97650a6d 00000000 00000000>}"
//代码
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
}
}