4

PHAsset has a creationDate property that gives the creation date of the asset in UTC.

If I take a photo taken at 10:52 PM UTC-6, the creationDate property is 03:52 AM.

How am I supposed to know the 'true' time of the photo taken? No timezone information is supplied with the creationDate property, so I can't adjust this back to 10:52 PM - I have no idea what time zone to just when adjusting it...

I know I can get the EXIF creation date (or attempt to at least) using PHImageManager requestImageDataForAsset and using the data returned there to obtain an EXIF creation date which actually is 10:52 PM, but this results in very slow for performance when the photos are in iCloud (I need this creation date value for all assets in the user's library). Additionally I cannot figure out how to get the EXIF creation date for videos.

I also know there are methods of obtaining a timezone from a CLLocation, which I could use to adjust the creationDate - but these methods are either rate limited and/or inaccurate

Is there another, easier way, to get this original creation date value?

To recap:

  • A photo is taken at 10:52 PM in UTC-6
  • PHAsset creation date is 03:52 AM in UTC
  • I want to know how to get 10:52 PM UTC-6 date/time.
Zach
  • 3,909
  • 6
  • 25
  • 50

2 Answers2

0

You can try using PHContentEditingInput. It will be probably slow for iCloud images too but it is worth trying as I don't think there are any other ways to do it :(

This approach does not require ImageIO import and needs less code so maybe it would be somewhat better than PHImageManager requestImageDataForAsset

You can use this PHAsset category to try it quickly: https://github.com/zakkhoyt/PHAsset-Utility

Heps
  • 945
  • 9
  • 24
0

Can get exif details as below :

let options = PHContentEditingInputRequestOptions()

asset.requestContentEditingInput(with: options) { input, _ in
    guard let url = input?.fullSizeImageURL else { return }
    guard let image = CIImage(contentsOf: url) else { return }
    guard let exif = image.properties["{Exif}"] as? [String: Any] else { return }

    print(exif["DateTimeOriginal"] ?? "")
    print(exif["SubsecTimeDigitized"] ?? "")
}

This prints:

2021:01:04 11:47:07

177

Nandish
  • 1,136
  • 9
  • 16