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.