Search code examples
iosswiftuiimagepickercontroller

How to get image name using UIImagePicker? I got image name but its working only in simulators not in actual devices


I need to pick the image name from photo library . I am using UIImagePicker and I got image name , but its working only in simulators not in actual devices.


Solution

  • Please try this: In your UIImagePickerControllerDelegate:

       func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let asset = info[UIImagePickerControllerPHAsset] as? PHAsset {
            let assetResources = PHAssetResource.assetResources(for: asset)
    
            print(assetResources.first!.originalFilename)
        }
    
        dismiss(animated: true, completion: nil)
    }
    

    It may helps you. Thank you.