How to get file name in UIImagePickerController with Asset library?

后端 未结 13 1640
天命终不由人
天命终不由人 2020-12-03 14:55

I want to get the file name from UIImagePickerController. I do not want to use ALAssetLibrary because it is deprecated in iOS 9. I have used the following code

13条回答
  •  无人及你
    2020-12-03 15:33

    You can try this for iOS 11

     func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let asset = info[UIImagePickerControllerPHAsset] as? PHAsset {
            if let fileName = (asset.value(forKey: "filename")) as? String {
                //Do your stuff here
            }
        }
    
        picker.dismiss(animated: true, completion: nil)
    }
    

    Make sure you add this NSPhotoLibraryUsageDescription to your Infor.plist

提交回复
热议问题