I am uploading a file in the background using the NSURLSession background session configuration.
- (void)initBackgroundSession { self.backgroundSessionManager = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:IELBackgroundSesssionCourseDownload] delegate:self delegateQueue:[NSOperationQueue mainQueue]]; [self updateCurrentDownloadingCourse]; self.isSuspendcourseDownloadTask = false; } - (void)updateCurrentDownloadingCourse { [_backgroundSessionManager getTasksWithCompletionHandler:^(NSArray<NSURLSessionDataTask *> * _Nonnull dataTasks, NSArray<NSURLSessionUploadTask *> * _Nonnull uploadTasks, NSArray<NSURLSessionDownloadTask *> * _Nonnull downloadTasks) { NSLog(@"Count of DownloadTask %lu",(unsigned long)downloadTasks.count); for (NSURLSessionDownloadTask *downloadTask in downloadTasks) { NSDictionary *customDescription = [downloadTask getCustomTaskDescription]; NSString *courseId = customDescription[IELCourseJSONKeyCoureID]; if (courseId) { [self setDownloadingCourse_id:courseId]; [self setCourseDownloadTask:downloadTask]; break; } [downloadTask resume]; } }]; }
Now the problem is that the download is in progress, and I close the application from the background by double-clicking the "Home" button. And then if I open the application again. Then the entire download will fail with the error message below. If I add the download task to the NSURLSession object again, then it will fail until I close the application from the background and open the application.
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSErrorFailingURLKey=https:
source share