How to retrieve PHAsset from UIImagePickerController

前端 未结 4 1037
予麋鹿
予麋鹿 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:37

    Here is my solution:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    
            if #available(iOS 11.0, *) {
                   let asset = info[UIImagePickerControllerPHAsset]
    
            } else {
                   if let assetURL = info[UIImagePickerControllerReferenceURL] as? URL {
                   let result = PHAsset.fetchAssets(withALAssetURLs: [assetURL], options: nil)
                   let asset = result.firstObject
                   }
           }
    }
    

提交回复
热议问题