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

10,900

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")

Share:
10,900
Iqbal Khan
Author by

Iqbal Khan

Updated on June 18, 2022

Comments

  • Iqbal Khan
    Iqbal Khan about 2 years

    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}
    
  • Iqbal Khan
    Iqbal Khan about 6 years
    the issue is that on next launch of the application does not allow to start downloading again, and each next download fails with same error.
  • Olof_t
    Olof_t almost 6 years
    on the next launch you get the errors for cancelling downloads by force-quit - so that is not an error. BUT it should allow you to start new ones. It looks like in the code that you are trying to re-use failed tasks, this could be the error.