Get URL path from UIImage - Framework ImagePicker

1.4k views Asked by At

I'm trying to get the path from UIImage (for multiple selections) which I just get from gallery using the framework ImagePicker. I get UIImage from this method:

func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
    //here I can recive the images from gallery   
}

On this func I need to save the path on a String

Thanks in advance

2

There are 2 answers

0
ielyamani On

A UIImage doesn't contain information about any URL or information about the path. You may save them in the documents directory of your app, and then you store the path in a variable.

I wouldn't recommend using a deprecated library, better use the default UIImagePicker and use this delegate method like so.

0
Igzar On

UIImage doesn't contain any information about asset URL. You should use UIImagePickerControllerDelegate imagePickerController(_:didFinishPickingMediaWithInfo:) for getting URL from info dictionary.

func imagePickerController(_ picker: UIImagePickerController, 
  didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    let imageURL = info[.imageURL] as? URL //here's your URL
}