0
votes

I have implemented the URLSessionDownloadDelegate and whenever my downloadTask fails i receive an error object in one of the delegate's callback methods. When i attach a debugger and print this error object to console, i can see that it contains ResumeData object in it. However i am not able to access it in code using error object.

This is the console output:

(lldb) po error.debugDescription "Optional(Error Domain=NSURLErrorDomain Code=-999 \"cancelled\" UserInfo={NSErrorFailingURLStringKey=https://mysampleurl, NSErrorFailingURLKey=https://mysampleurl, NSURLSessionDownloadTaskResumeData=<3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 21444f43 54595045 . . . 692c2031 37204a75 6e203230 31362031 373a3433 3a303120 474d543c 2f737472 696e673e 0a3c2f64 6963743e 0a3c2f70 6c697374 3e0a>, NSLocalizedDescription=cancelled})"

I want to access "NSURLSessionDownloadTaskResumeData" from the error object output above

The method definition is :

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

1

1 Answers

1
votes

I recently worked on this requirement and I created a class : https://github.com/skdevil/PrakrstaFileDownloader

This how you get resumeData :

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
        if error != nil{
            let errorString = (error! as NSError).userInfo
            if let resumeData = errorString["NSURLSessionDownloadTaskResumeData"] as? Data, let urlKey = errorString["NSErrorFailingURLStringKey"] as? String {

            }
        }
    }