Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLSession Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"

I am downloading the file in background using 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 issue is if a download is in progress and i close the application from background by pressing home button twice. And then if i reopen the application. Then all download starts failing with given below error message. If i re-add a download task in the NSURLSession object even then it fails till i close application from background and reopen 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://ilmsdevqa.inspiredlms.com/Content/Organizations/1544/ScormCourses/offline/2970-offline.zip, NSErrorFailingURLStringKey=https://ilmsdevqa.inspiredlms.com/Content/Organizations/1544/ScormCourses/offline/2970-offline.zip}
like image 369
Iqbal Khan Avatar asked Oct 10 '17 13:10

Iqbal Khan


1 Answers

If you force-quit the app, all background downloads will be canceled and generate this error. It's in the docs.

(Guessing that's what you mean by "I close the application from background by pressing home button twice")

like image 113
Olof_t Avatar answered Oct 04 '22 12:10

Olof_t