Download resuming failed in NSUrlSession on iOS10

I implemented a background downoading feature in my application, during test I discovered that background downloading is not resuming in iOS 10 only. Code worked well on previous version (below iOS 10). I could not find any solution for this issue.


When Internet is down then in "didCompleteWithError" delegate I add this code to cancel by producing Resume Data


-(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error{


[self.fdi.downloadTask cancelByProducingResumeData:^(NSData *resumeData) {

taskResumeData = (NSData *)[[error userInfo]objectForKey:@"NSURLSessionDownloadTaskResumeData"];

}];


}


After Internet connection avaible I call this method - (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData; for resuming downloading using resumedData.



downloadTask = [APP_DELEGATE.downloadManager.session downloadTaskWithResumeData:taskResumeData];

[downloadTask resume];





After calling above method we get this error:



Error on cosole:


2016-09-20 17:28:04.126863 BigFlix[3253:591639] -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

2016-09-20 17:28:04.127684 BigFlix[3253:591639] -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

2016-09-20 17:28:04.419939 BigFlix[3253:591639] Invalid resume data for background download. Background downloads must use http or https and must download to an accessible file.

Replies

You are not alone. I've just now noticed the same issue in my App as well. Resuming background downloads does no longer work under iOS 10. I do get the same messages in the console and the error that is reporting the failure in the delegate URLSession:task:didCompleteWithError: is always NSURLErrorCannotWriteToFile.

When debugging in the Simulator I can see that there is actually a file created for each download that is started (in the folder Library/Caches/com.apple.nsurlsessiond/Downloads/<app.bundle.id>/ of the App). And these files remain there, these are not deleted, so when the iOS tries to resume the download it should theoretically have all the needed data to resume.

There no such issue under iOS 8 or 9.

Same here. I found 2 issues.


Firstly cancelByProducingResumeData then resume, the resumeData whilst assigned, did not work. I was able to find this explanation and use the workaround: http://stackoverflow.com/a/39347461/1012802.


2nd, as BigSunil describes, whilst a task is downloading, and the network is turned off, the error's userInfo should contain the NSURLSessionDownloadTaskResumeData, but it doesnt. Also, the error's localizedDescription should be 'cancelled', but instead is 'unsupported URL'. Unfortunately I have not found a workaround for this.


I've logged bug reports: 28003939 and 28447649 respectively. I reported 28003939 on the beta6 back in august and it has been marked a duplicate of 27744391, ive also read this bug was as early as beta1.


I have to say, I've lost alot of respect for Apple hanging our apps out like this, with no feedback on bug reports or notes in changelogs for workarounds. But I'm sure i'm not the first.

Thanks for the link to stackoverflow. This might at least help in my case.

Hello,


I have the same issue with resuming downloads on iOS 10. The resume just does not work. The stackoverflow link may help .. but I think that it is not for production code. The resume data has to be maintained by iOS and must be correct. I cannot understand how can it happen to fail such an easy-to-test use-case.


Am I doing something terribly wrong? Until iOS 10 resume does work.


Apple please help.


Regards,

Mihai

The bug is in iOS 10, so it's not your fault. Apple has to fix this.


But until they do, I will use the approach from the Stackoverflow link in my App to correct the corrupt resume data. Users of your App will blame you for the failure, not Apple, therefore if there is a workaround, even such a hack, I would use it.


But also don't forget to send a bug report to Apple. The more developes report a bug, the more likely that Apple will take the issue serious.

You are partly right, but there is another problem that affects background downloads: if the network becomes unavailable during the download all your downloads will be cancelled with error NSURLErrorUnsupportedURL and without resume data. In this case there is no workaround.


I also reported the issue to Apple. We hope to get the fix soon.

Is this still an issue in the official release of iOS 10? Or was this fixed?

This is still very much broken )-: The iOS 10 side of the fix is being tracked as 27744391. At this point it looks like it won’t catch the 10.1 bus, so we’ll have to live with this for a while )-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The issue still exists in iOS 10.1

Same issue, here still exists in 10.1.


We really need information on a fix from Apple now.

Any updates on this would be much appreciated. Did it make it into iOS 10.1.1, or will it be iOS 10.2 ?

The iOS 10 side of the fix is being tracked as 27744391. At this point it looks like it won’t catch the 10.1 bus …

27744391 is reported as fixed in the current 10.2 beta seed (14C5062e). If you’re having problems with:

  • explicit resumes failing with

    NSURLErrorCannotWriteToFile
    (-3003)
  • downloads failing with

    NSURLErrorUnsupportedURL
    (-1002) after a network connectivity failure

please try again on that seed and, if you still see problems, please file a bug and post the bug number here.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you! I will install the beta and test it asap.

It is working now, thanks.

Same issue, here still exists in 10.1.