Ios downloaded locations

I develop an App which has a quicklook preview for files located on a web server To realize this preview, I download the file and access it with a QLPreviewController

When I use simulator, I can see the downloaded files somewhere in library/developper/coresimulator..... and so on of my mac, and I can manually delete them. But if I search these files on the IPhone simulator, I can't find them.

What when I run the application on my real device? How will I be able to delete these files? because I think it take place in the IPhone

I download the file

Download the file how?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I download the file with Alamofire:

public func downloadFile(request: BaseRequest, progressIndicator: UIProgressView?, completion: @escaping(NetworkResult<String,  NSString>) -> Void) {
        if let progressIndicator = progressIndicator {
            progressIndicator.isHidden = false
            progressIndicator.progress = 0
        }
        if let filename = request.parameters["filename"], let displayName = request.parameters["displayname"], let url = URL(string: filename.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) {

            let destination: DownloadRequest.Destination =  { _, _ in
                var documentsURL: URL!
                if request.parameters.keys.contains("destination") {
                    let dest = "file://\(request.parameters["destination"]!)"
                    documentsURL = URL(string: dest.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
                } else {
                    documentsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
                    documentsURL.appendPathComponent(displayName)
                    documentsURL = URL(string: filename.replacingOccurrences(of: "file://", with: "").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
                    documentsURL = URL(string: filename.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
                }
                return (documentsURL, [.removePreviousFile])
            }
            AF.download(url, to: destination)

                .downloadProgress(queue: .main, closure: { (progress) in
                    if let progressIndicator = progressIndicator {
                        DispatchQueue.main.async {
                            progressIndicator.progress = Float(progress.fractionCompleted)
                        }
                    }
                })

                .responseData {
                    response in
                    progressIndicator?.isHidden = true
                    switch response.result {
                    case .failure(let error):
                        completion(NetworkResult.failure(NSString(string: error.errorDescription!)))
                    case .success(_):
                       completion(NetworkResult.success(response.fileURL?.path ?? ""))
                    }

                }

        } else {
            completion(NetworkResult.failure(NSString(string: "Impossible de récupérer le fichier, requête \(request)")))
        }
    }

I download the file with Alamofire

I’m not familiar with the details of that library, other than that I know it works on top of URLSession. The URLSession model for downloads is:

  • The system downloads the file to a temporary location.

  • When it’s done, it calls you back with the location of the downloaded file.

  • You can choose to copy or move the file.

  • When your callback returns, if you didn’t move the file, the system deletes it.

In this model you are in control of the final location of these downloaded files and you can choose to manage them however you want.

If you need help understanding how a specific third-party library exposes that model to you, I recommend you raise that via its support channel.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I'm not sure the system deletes the file, immediately, because after downloading it, I use Quicklook to preview this file, and it works. and in the procedure where AlamoFire is called, there are thse lines:

if request.parameters.keys.contains("destination") {
                    let dest = "file://\(request.parameters["destination"]!)"
                    documentsURL = URL(string: dest.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
                }

and I fixed the destination parameter to .DocumentDirectory

But After all you're right: I will ask the question to Alamofire developpers Thank's

Ios downloaded locations
 
 
Q