I am using ImageCaptureCore to access and (sometimes) download media files from a digital camera connected via USB (either to a Mac oder to an iOS device with Apple lightning to USB3 camera adapter).
This works very well in general, but what puzzles me is that for the ICCameraFile's EXIF creation/modification date, it always returns nil. I can access the ICCameraItem's creation/modification date instead, which, as it says in the documentation "usually [is] the same as its EXIF creation date", but, well not always. Generally the EXIF tags are more reliable than the file dates, especially the modification date is easily messed up when copying files.
As for my cameras, they show the stable EXIF date on their display, so for consistency I would prefer to use the same in my app. Is there a way to get it without downloading the image from the camera and reading it from the file?
Does it possibly depend on the brand of camera (I mostly have Canon) whether ICCameraFile.exifCreationDate
is ever populated or always nil?
For a thumb drive with DCIM folder, which is treated just like a camera, it is also nil.
Thanks for asking. Are you able to verify that the EXIF creation/modification you are not able to receive from Core Image are present using the EXIF tab in the Preview app's Inspector? If so, this may be a bug.
If you can see these dates in Preview but not when calling the Core Image APIs, our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. Please open a bug report, include a small Xcode project that includes one of your images with its EXIF data, and post the FB number here once you do.
Bug Reporting: How and Why? has tips on creating your bug report.
In the interim, you may also wish to try the Image I/O APIs to check your EXIF data. Here is how you can use Image I/O to extract get the EXIF data from an image file:
guard let image_data_source: CGImageSource = CGImageSourceCreateWithURL(theURL as CFURL, nil) else {
throw .errorCreatingImageSource(theURL) }
guard let sourceProps = CGImageSourceCopyPropertiesAtIndex(image_data_source, 0, [:] as CFDictionary) as? [AnyHashable: Any] else {
throw .errorGettingImageProperties(theURL) }
if let exif_data: [AnyHashable : Any] = sourceProps[kCGImagePropertyExifDictionary] as? [AnyHashable : Any] {
// using kCGImagePropertyExifDateTimeOriginal and kCGImagePropertyExifDateTimeDigitized keys...
}
Note, the EXIF standard seems to have two keys that appear to be relevant in this case.
- kCGImagePropertyExifDateTimeDigitized ("DateTimeDigitized") is defined as the time when the image was stored as digital data
- kCGImagePropertyExifDateTimeDigitized ("DateTimeOriginal") is defined as the time when the original image was generated.
I suggest doing a double check to verify your camera is providing the one you are using.