nullpointr
nullpointr

Reputation: 532

Load Specific Image From Path After It Was Saved To Camera Roll

I use UIImagePickerController to save image to photo album which was taken by camera.

UIImageWriteToSavedPhotosAlbum(myImage, self, #selector(saveimage(_:didFinishSavingWithError:contextInfo:)), nil)

The image is successfully saved to photo album with name like IMAGE_4000.JPG. I want to get the path to load the image directly without picking it implementing UI-based user selection.

I tried to do the following, but it only gives me access to the app's specific folder (like /var/mobile/Containers/Data/Application/3C739746-<...>/Documents/) and not to photo album.

let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let fullpath = path[0].appending("/IMAGE_4000.JPG")
let url = URL(fileURLWithPath: fullpath)
let imagedata = try? Data(contentsOf: url)
let imagefromstorage = UIImage(data: imagedata!)

So my question is, how can I get the image name after it was saved via UIImageWriteToSavedPhotosAlbum and the photo album path to access it like I described in the above code snippet?

Upvotes: 0

Views: 175

Answers (1)

Jaydeep Vora
Jaydeep Vora

Reputation: 6213

UIImageWriteToSavedPhotosAlbum will save the image to the Camera Roll album. which is a different container.

let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)

and the above statement will search the file in your App container.

So both are different things.

Upvotes: 0

Related Questions