PHPickerViewController - can't get URL from PHPickerResult

Hi,

I have a little issue with this new API PHPPickerViewController:

Code Block
 var configuration = PHPickerConfiguration()
 configuration.filter = .any(of: [.images])
 configuration.selectionLimit = 10
 configuration.preferredAssetRepresentationMode = .compatible
let picker = PHPickerViewController(configuration: configuration)
 picker.delegate = self
 present(picker, animated: true, completion: nil)


Code Block
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
  var selectedPhotosData : [Data] = []
  for (index,result) in results.enumerated() {
result.itemProvider.loadFileRepresentation(forTypeIdentifier: "public.jpeg") { (url, error) in
    guard let fileUrl = url else {return }
print(fileUrl)
     }
}


This code above doesn't work, I don't get the URL at all. I tried on Simulator and real device but the same problem. I tried loadObject function but I can't the UIImages...

I saw some workarounds here but they don't work in my case it seems...
Are you sure you have chosen images of jpeg format?

As far as I tried, I could not get a URL for heic image with your code, but could get URLs for jpeg image.

Please try:
  • configuration.preferredAssetRepresentationMode = .current

  • Use UTType.image.identifier ("public.image") for type identifier

I tried that now. Doesn't work. I still get nil on URL on both device and simulator


PHPickerViewController - can't get URL from PHPickerResult
 
 
Q