How to get thumbnail / preview image for items imported from PHPicker?

I am starting to use NSItemProvider methods hasRepresentationConforming and loadFileRepresentation for importing images, live photos and videos from PHPicker on iOS.

I would like to generate thumbnails / preview images for each imported image, live photo and video. I tried using theNSItemProvider method loadPreviewImage, but in testing with Xcode Version 12.0 (12A7209) in iOS 14 Simulator, the NSItemProvider.CompletionHandler always returns nil for the item regardless of whether I use NSData, NSURL or UIImage.

Is it best to generate thumbnails by scaling down imported images with UIGraphicsBeginImageContext and use AVAssetImageGenerator on imported videos?
Answered by owjhart in 641403022
Update: For now, I have decided to go with using QLThumbnailGenerator to create thumbnails for resources imported from PHPicker. In the future, this generator should be very easy to swap out for NSItemProvider method loadPreviewImage if that starts working on PHPicker.
Update: In testing with Xcode 12.0.1, running on a physical device with iOS 14.0.1, loadPreviewImage also returns nil in the completion handler.
Accepted Answer
Update: For now, I have decided to go with using QLThumbnailGenerator to create thumbnails for resources imported from PHPicker. In the future, this generator should be very easy to swap out for NSItemProvider method loadPreviewImage if that starts working on PHPicker.

I was also getting nil values when using NSItemProvider method loadPreviewImage. I tested on device as well as simulator(iOS version 15.5 and 15.2). Has anyone seen this issue persisting in current versions of iOS

    func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {         picker.dismiss(animated: true, completion: nil)         if let itemProvider = results.first?.itemProvider {             if(itemProvider.hasItemConformingToTypeIdentifier(UTType.image.identifier)) {                 itemProvider.loadPreviewImage { secureCoding, error in                     print("I am getting (secureCoding) and (error)")                 }             }         }     }

Output: I am getting nil and nil

How to get thumbnail / preview image for items imported from PHPicker?
 
 
Q