I have generated a URL with the following function below. I would like to save this to the local folder for use later on. However, when I save it to the local folder, and then retrieve it, the URL is truncated. Please can someone advise on how I would be able to save and extract the full URL?
func createPhotoURL() -> URL {
let fileName = "tempImage_wb.jpg"
let documentsDirectories = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentDirectory = documentsDirectories.first!
let pdfPageURL = documentDirectory.appendingPathComponent("\(fileName)")
return pdfPageURL
}
When I call the function I get the full length URL:
let imageURL = createPhotoURL() // CORRECT URL FOR FILE UPLAOD
print("imageURL: \(imageURL)")
Console:
file:///var/mobile/Containers/Data/Application/CDDE2FED-5AAB-4960-9ACF-33E7B42D05AE/Documents/tempImage_wb.jpg
Save above URL to local folder and the retrieve it:
UserDefaults.standard.set(imageURL, forKey: "URL_IMAGE")
guard let retrievedURL = UserDefaults.standard.string(forKey: "URL_IMAGE") else{return}
print("retrievedURL: \(retrievedURL)")
Console:
retrievedURL: ~/Documents/tempImage_wb.jpg