I want to get the file name from UIImagePickerControllerPHAsset in ios 11.0.3. unable to get picked image file name using this code. please help on this?
if #available(iOS 11.0, *) {
let asset = info[UIImagePickerControllerPHAsset] as? PHAsset
fileName = ((asset?.value(forKey: "filename")) as? String)!
} else {
// Fallback on earlier versions
let url = info[UIImagePickerControllerReferenceURL] as! URL
let assets = PHAsset.fetchAssets(withALAssetURLs: [url], options: nil)
fileName = PHAssetResource.assetResources(for: assets.firstObject!).first!.originalFilename
}
Getting crashes on fileName = ((asset?.value(forKey: "filename")) as? String)!
You can try this...
if #available(iOS 11.0, *) {
let asset = info[UIImagePickerControllerPHAsset] as! PHAsset
var resources = PHAssetResource.assetResources(for: asset)
var orgFilename = (resources[0]).originalFilename
print("File Name: ",orgFilename)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With