0

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:

  • select (and display) a photo from the Camera Roll. (But I don’t know what info lets me reselect the image, something like an image path and name in the desktop world. This is the heart of my question.)
  • create an array and append new items. (I assume I could append a string or object identifying an individual photo.)
  • randomly select an item from an array
  • display an image

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

Community
  • 1
  • 1
Al C
  • 5,175
  • 6
  • 44
  • 74

2 Answers2

1

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).

Imran
  • 2,985
  • 19
  • 33
0

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.

Scott H
  • 1,509
  • 10
  • 14