In my app, I allow the user to take a photo with the camera. When didFinishPickingMedia executes, I want to save the photo to the FILE LOCATION (url... modelController.saveLocation) the user previously selected earlier in the app. The file location may be a folder in File Directory, Dropbox, etc. I can't seem to figure out how to do this, despite my reading efforts online. The other tutorials seem to be taking a photo that's in the assets folder and saving it somewhere, not a photo that was just taken.
I tried this code, but it doesn't work. The code in the catch statement is called due to some error.
let url = modelController.saveLocation[0].appendingPathComponent("(saveLocationName.description).jpg")
if let data = image.jpegData(compressionQuality: 1.00) {
do {
try data.write(to: url)
} catch {
print("Unable to write image data to disk")
selectNewFileLocation()
}
}
Please explain your answers with code. It's probably a really simple solution, but I'm a rookie. Thanks for your help ahead of time!
question from:
https://stackoverflow.com/questions/66054858/save-camera-photo-to-file-location-swift-xcode 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…