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)!