I am trying to find a reliable way of accessing the Creation Date & Location Data from an image selected from Photos. I wrote a demo app and everything seemed to work fine for some initial tests the code is as follows:
//selected Image
func imagePickerController(_
picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let uiImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
image = Image(uiImage: uiImage)
if let asset: PHAsset = info[UIImagePickerController.InfoKey.phAsset] as? PHAsset {
print("Asset: \(asset)")
print("Creation Data \(String(describing: asset.creationDate))")
print("Location: \(String(describing: asset.location))")
} else {
print("Asset: nil")
}
isShown = false
}
Originally this was correctly showing the creation data and location data but unfortunately it has now stopped working, the line:
if let asset: PHAsset = info[UIImagePickerController.InfoKey.phAsset] as? PHAsset {
Always returns nil
Could this be down to permissions? The info.plist file contains the following:
Privacy - Photo Library Usage Description
Privacy - Photo Librar Additions Usage Description
I know the image contains the relevent data because if I open the image in Photos it shows it location on a map
Is there a better way? Ideally I want to store the image in CoreData along with its creation data and location. On Andriod I would simply store the image as a .jpeg file and pull the info from the image after loading it.