I used swift code to download a PDF file. It says that it is saved to destiantion
file:///var/mobile/Containers/Data/Application/25E45F2F-41EA-4EAB-8D8A-97F43A209D36/Documents/model-1.pdf
However when I open files from my iPhone I cannot find the file named "model-1.pdf" anywhere.
The code I used was from : Download file from server using Swift
let documentsUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
// your destination file url
let destination = documentsUrl.appendingPathComponent(pathURL.lastPathComponent)
print(destination)
// check if it exists before downloading it
if FileManager().fileExists(atPath: destination.path) {
print("The file already exists at path")
} else {
// if the file doesn't exist
// just download the data from your url
URLSession.shared.downloadTask(with: pathURL, completionHandler: { (location, response, error) in
// after downloading your data you need to save it to your destination url
guard
let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
let location = location, error == nil
else {
self.showAlert(title: NSLocalizedString("Error", comment: "") , message: "")
return }
do {
try FileManager.default.moveItem(at: location, to: destination)
print("file saved")
} catch {
print(error)
}
}).resume()
}