I have an app using a backgroundSessionConfiguration
instance of NSURLSession
to handle some NSURLSessionDownloadTask
tasks. The tasks are created correctly, and finish downloading, but in URLSession:downloadTask:didFinishDownloadingToURL:
when I go to move the downloaded file from location
to a permanent spot on disk, I sometimes (read: often) get the error:
NSUnderlyingError=0x178247890 "The operation couldn’t be completed. No such file or directory"
It's as though the downloaded file is being cleared out of the temp directory (../Library/Caches/com.apple.nsnetworkd/..) before I get a chance to move it.
Running the operation for the same remote file will behave both ways with all other factors being equal, so I haven't been able to identify anything that would cause it to sometimes work.
Is there anyway to ensure that this file will stick around long enough to move it into place once it's done?
Edit: I'm also seeing this with some frequency for normal (not background) sessions as well