tp2376
tp2376

Reputation: 740

URLSession Error when Downloading file failed because of less memory In phone

I am trying to download file from my App and I have a Question About it what happens if phone has less memory than file size that is being downloading..

Is It trigger below urlSession delegate ? If it is what is the error?

 public func urlSession(_ session: URLSession, task: URLSessionTask, 
   didCompleteWithError error: Error?) {
}

Upvotes: 1

Views: 775

Answers (1)

rmaddy
rmaddy

Reputation: 318814

According to NSURLSessionDownloadTask issues with Storage almost full disk warnings and https://forums.developer.apple.com/thread/43263 it would seem that you will get an error and its domain will be NSPOSIXErrorDomain with an error code of ENOSPC (Error, No Space).

There is also the possibility of getting an error with the domain of NSCocoaErrorDomain and an error code of NSFileWriteOutOfSpaceError.

public func urlSession(_ session: URLSession, task: URLSessionTask,  didCompleteWithError error: Error?) {
    if let nserror = error as? NSError {
        if (nserror.domain == NSPOSIXErrorDomain && nserror.code == ENOSPC) ||
           (nserror.domain == NSCocoaErrorDomain && nserror.code == NSFileWriteOutOfSpaceError) {
            // Not enough space
        }
    }
}

Upvotes: 2

Related Questions