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

3

8

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}
Leotie answered 10/10, 2017 at 13:27 Comment(4)
facing the same issuePettaway
I too facing the same, Any success?Mineraloid
i did not found any solution for this issue. But this issue mostly happens when i have debugger attach.Leotie
I am also facing the similar issue :(Leftward
S
3

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

Semitics answered 25/6, 2018 at 21:4 Comment(2)
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.Leotie
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.Semitics
G
0

I had a similar issue, not the exact same, but found this questions through a Google search - here's the error code and one solution.

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

Fix: Sign the app with an Apple Developer Id - https://developer.apple.com/developer-id/

Hack-fix:

sudo spctl --master-disable
Grecoroman answered 6/6, 2019 at 20:27 Comment(0)
P
0

In my case, the same error appeared when I changed connected device and ran the app thru Xcode on another iPhone. Quitting Xcode and opening again solved the issue and the app now runs normal on the new device.

Parrott answered 1/10, 2021 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.