How to retrieve PHAsset from UIImagePickerController

前端 未结 4 1039
予麋鹿
予麋鹿 2021-02-07 12:42

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?

4条回答
  •  别跟我提以往
    2021-02-07 13:33

    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
    

提交回复
热议问题