1

I am using share extension in my application and I want to show image taken time while I am sharing image with share extension.Is there any way to get the time of image when we use share extension.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Deepak Saki
  • 945
  • 1
  • 8
  • 16

1 Answers1

1

The timestamp is available in EXIF data stored with the images. You can get it using UIImagePickerController like this:

https://stackoverflow.com/a/33672661/4042468

On the other hand, if you have image file url, you can use import ImageIO and the below code to get all the properties of the image of which date time is one.

if let imagePath = Bundle.main.path(forResource: "test", ofType: "jpg") {
        let imageURL = NSURL(fileURLWithPath: imagePath)

        if let imageSource = CGImageSourceCreateWithURL(imageURL, nil) {
            if let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: AnyObject] {

            }
        }
    }

Note that there is a Exif key in which you can find timestamp.

Community
  • 1
  • 1
kerry
  • 2,362
  • 20
  • 33