NSURLSession didFinishDownloadingToURL temporarily uploaded file not found

I had a strange problem with NSURLSession by the didFinishDownloadingToURL delegation method.

The first thing I do is to check if a temporary uploaded file exists:

- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { if (![[NSFileManager defaultManager] fileExistsAtPath: [location path]]) { NSLog(@"Error. File not found"); return; // is giving error when the app is wake up by the system } ... } 

It works fine when the application is in the foreground and the download ends. But when the application is in the background and is forcibly killed by the operating system, it returns false.

Does anyone have an idea of ​​what might happen? I know that there is a time limit for executing this delegate method when the application wakes up by the operating system since there is no temporary file for the temporary file. I can’t even copy it to another place ... Does it make sense to be due to file size? I upload a file + -130MB.

Thanks.

+7
ios objective-c download nsurlsession
source share
2 answers

I solved the same problem by installing the application after uninstalling the application. It seems that NSURLSession leaves garbage on the system when forced termination occurs while the network session is running.

+1
source share

From Apple Docs :

( location is ..) "The URL of the file for the temporary file. Since the file is temporary, you must either open the file for reading or move it to a permanent location in the container directory for application sandboxes before returning with this delegate method.

If you decide to open the file for reading, you must do the actual reading in another thread to avoid blocking the delegate queue. "

-2
source share

All Articles