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
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
var selectedFileName = ""
if #available(iOS 11.0, *) {
if let imageUrl = info[.imageURL] as? URL {
selectedFileName = imageUrl.lastPathComponent
}
} else {
if let imageURL = info[.referenceURL] as? URL {
let result = PHAsset.fetchAssets(withALAssetURLs: [imageURL], options: nil)
if let firstObject = result.firstObject {
let assetResources = PHAssetResource.assetResources(for: firstObject)
selectedFileName = assetResources.first?.originalFilename
}
}
}
picker.dismiss(animated: true, completion: nil)
}