Al C
Al C

Reputation: 5377

How can you identify an image selected from the camera roll?

I’d like to make an app where users (1) select an arbitrary number of photos from the Camera Roll, and then (2) randomly select (and display) one of the photos. I know how to:

I did see this question but it's several years old.

Upvotes: 0

Views: 219

Answers (2)

Imran
Imran

Reputation: 2941

As you said you know how to select (and display) a photo from the Camera Roll so when you select following delegate method is called .

optional func imagePickerController(_ picker: UIImagePickerController,
      didFinishPickingMediaWithInfo info: [String : AnyObject])

which has info parameter that is a dictionary. Info Dictionary have following keys

let UIImagePickerControllerMediaType: String
let UIImagePickerControllerOriginalImage: String
let UIImagePickerControllerEditedImage: String
let UIImagePickerControllerCropRect: String
let UIImagePickerControllerMediaURL: String
let UIImagePickerControllerReferenceURL: String
let UIImagePickerControllerMediaMetadata: String

You can check UIImagePickerControllerMediaURL for the path. If you need more then this info you can consider using Assets Library Framework that have much more information about the Assest (including photos).

Upvotes: 1

Scott H
Scott H

Reputation: 1529

In my experience when working with the camera roll via UIImagePickerViewController, what you receive is a URL to the image after it has been copied into your app's sandbox (I believe it's in the "tmp" folder, but it might be something else).

So after the user selects the photos, you can store these URLs to retrieve the image later. If you need these images to persist beyond a single run of your app, then you should consider moving them to a permanent folder in your sandbox so as not to be accidentally deleted by you or iOS. In this case I would would create a specific folder for the images and scan this folder on each app launch to determine what images are available.

Upvotes: 0

Related Questions