How to retrieve PHAsset from UIImagePickerController

Peter Warbo picture Peter Warbo · Jul 7, 2017 · Viewed 8.2k times · Source

I'm trying to retrieve a PHAsset however PHAsset.fetchAssets(withALAssetURLs:options:) is deprecated from iOS 8 so how can I properly retrieve a PHAsset?

Answer

Andrew Geisthardt picture Andrew Geisthardt · Oct 4, 2017

I had the same the issue, first check permissions and request access:

let status = PHPhotoLibrary.authorizationStatus()

if status == .notDetermined  {
    PHPhotoLibrary.requestAuthorization({status in

    })
}

Just hook that up to whatever triggers your UIImagePickerController. The delegate call should now include the PHAsset in the userInfo.

guard let asset = info[UIImagePickerControllerPHAsset] as? PHAsset