Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLSession didFinishDownloadingToURL temporary downloaded file not found

I'm having a strange issue with NSURLSession on the delegate method didFinishDownloadingToURL.

First thing I'm doing is check if the temporary downloaded file exist:

- (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 normally when the app is in foreground and download finishes. But when the app is in background and is killed forcedly by the operating system, it returns false.

Does anyone have any idea about what might be happening? I know that there is a time limit for the execution of this delegate method when the app is wake up by the operating system, by it makes no sense for the temporary file to be not there. I can't even copy it to another location... Does it make sense to be because of the size of the file? I'm downloading a file of +-130MB.

Thanks.

like image 584
Guilherme Gusman Avatar asked Mar 04 '15 16:03

Guilherme Gusman


1 Answers

I solved the same problem by installing app after uninstall app. It seems that the NSURLSession leaves debris on system when forced shutdown happens while a network session working.

like image 67
TGT Avatar answered Nov 10 '22 04:11

TGT