Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

ios - Save Camera Photo To File Location - Swift Xcode

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...