UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Accessing Image EXIF Data (Creation Date & Location) of an image

Forums > SwiftUI

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.

6      

I'm having the same issue, did you ever find a solution @markpuk?

3      

How do you do this with the new PHPhotoPicker in ios14? I need to change the creation date of images which are loaded with the PHPhotoPicker.

3      

I created a blog post about it. Feel free to check it out: https://www.felixlarsen.com/blog/photo-metadata-phpickerview

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.