How to obtain UIImage from PHLivePhoto?

Inside

func picker(_ picker: didFinishPicking results:)

I am trying to obtain a UIImage from a Live Photo. I have parsed the results and filtered by regular still photos and live photos. For the still photos, I already have the UIImage but for the live photos I do not understand how to get from a PHLivePhoto to the PHAsset.

if let livePhoto = object as? PHLivePhoto {
  DispatchQueue.main.async {
    // what code do I insert here to get from PHLivePhoto to a UIImage? I need to extract a UIImage from a PHLivePhoto
  }
}

Thanks for the help in advance!

Accepted Answer

Option 1:

You can load the image and the Live Photo separately via the item provider:

e.g.

let itemProvider = result.itemProvider

let imageProgress = itemProvider.loadObject(ofClass: UIImage.self) { image, error in
    // do something with the image
}

let livePhotoProgress = itemProvider.loadObject(ofClass: PHLivePhoto.self) { livePhoto, error in
    // do something with the Live Photo
}

Option 2:

You can also use PHAssetResource.assetResources(for: livePhoto).

How to obtain UIImage from PHLivePhoto?
 
 
Q