If I create a DownloadTask by nsurlsession, there was a tmp file named like 'CFNetworkDownload_1vY41L.tmp'
in /Developer/tmp/ folder.
Then how to delete the tmp file when I delete downloadTask?
Moreover, I don't want to delete all tmp file because there are other downloadTask cache file.
Apple's documentation says that the file will be deleted once the download block finishes, check location explanation. And yes it is deleted, at least in iOS 12, you have to move it before it completes, no need to free space.
Example:
let task = self.session.downloadTask(with: request) { [weak self] url, response, error in
if let error = error {
...
}
guard let httpResponse = response as? HTTPURLResponse else {
fatalError("Couldn't get HTTP response")
}
if 200..<300 ~= httpResponse.statusCode, let downloadedPath = url {
// Move file in downloadedPath to a documents or other location
}
}
downloadPath will have the location of the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With