UIImagePickerControllerReferenceURL was deprecated in iOS 11 (even though it's still returned in the info dictionary) and was supposed to be replaced with UIImagePickerControllerPHAsset, but I've yet to get an info dictionary back which contains that key. Since the one is deprecated and the other is missing, is there a known solution for extracting the "date taken" from the picked image?
For reference, this is an example info dictionary returned when and image is picked from the library:
▿ 4 elements
▿ 0 : 2 elements
- key : "UIImagePickerControllerImageURL"
- value : file:///private/var/mobile/Containers/Data/Application/EE1BA60E-2DC3-47C5-A58D-86498E95C323/tmp/3A025D4C-B378-474B-8A09-017479A3A776.jpeg
▿ 1 : 2 elements
- key : "UIImagePickerControllerMediaType"
- value : public.image
▿ 2 : 2 elements
- key : "UIImagePickerControllerReferenceURL"
- value : assets-library://asset/asset.HEIC?id=537976CD-A550-41C9-9416-92C8072112D7&ext=HEIC
▿ 3 : 2 elements
- key : "UIImagePickerControllerOriginalImage"
- value : <UIImage: 0x1d04b4760> size {3024, 4032} orientation 3 scale 1.000000
(Note that UIImagePickerControllerReferenceURL is still present, though deprecated, and the suggested replacement, UIImagePickerControllerPHAsset, is missing.)
If it were present, getting the date would be simple:
if let asset = info[UIImagePickerControllerPHAsset] as? PHAsset,
let resource = PHAssetResource.assetResources(for: asset).first {
let dateTaken = resource.creationDate
}
Could it be that Apple forgot to implement UIImagePickerControllerPHAsset? Any ideas on workarounds (without using deprecated methods)?
Note on possible duplicates
I believe that previous solutions on Stack Overflow are deprecated, and thus won't answer the question using modern approaches.