NSURLSession Error Domain = NSPOSIXErrorDomain Code = 2 "There is no such file or directory"

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://ilmsdevqa.inspiredlms.com/Content/Organizations/1544/ScormCourses/offline/2970-offline.zip, NSErrorFailingURLStringKey=https://ilmsdevqa.inspiredlms.com/Content/Organizations/1544/ScormCourses/offline/2970-offline.zip} 
+6
source share
2 answers

If you forcefully close the application, all background downloads will be canceled and will generate this error. This is in the docs.

(I assume that you mean "I close the application from the background by double-clicking the home button")

+1
source

I had a similar problem, but not the same, but I found these questions through a google search - here is the error code and one solution.

 Error Domain=NSCocoaErrorDomain Code=260 "The file "PlugIns" couldnt be opened because there is no such file." ... NSUnderlyingError= ... {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} 

Bugfix: sign the application using Apple Developer Id - https://developer.apple.com/developer-id/

Hack fix:

 sudo spctl --master-disable 
0
source

Source: https://habr.com/ru/post/1272500/


All Articles