Preserving and Updating Image EXIF data in iOS

By
StartxLabs

Date
06-01-18

"
Preserving and Updating Image EXIF data in iOS"

EXIF metadata helps to gather information about an image like camera shutter speed, date and time when the image was taken, geolocation etc. which helps photographers to create the similar environment when an image was taken or it could help people to utilize that information as per there need.

But, it is usually seen that pictures that are saved in iOS get their EXIF data stripped off if it is not saved properly, so here is a go through on how to preserve EXIF data.

To save camera image in photo library using PHPhotoLibrary and to save EXIF into image metadata get the image media metadata which is provided by the iOS you can view by using UIImagePickerControllerMediaMetadata from info which is provided by the imagepickerviewcontroller didFinishPickingMediaWithInfo and you can append the metadata by creating mutable data of EXIF.

The kCGImagePropertyGPSLatitude and kCGImagePropertyGPSLongitud does not store negative value so we have to convert the negative value to positive and fetch correct lat and long, we need to store the reference of latitude and longitude in kCGImagePropertyGPSLatitudeRef and kCGImagePropertyGPSLongitudeRef and to get correct lat and long we will use the reference of lat and long which is saved above

And when you will pick image from gallery then it contains positive value of latitude and longitude so we need to set its correct value for calculating the average of latitude and longitude, you can achieve this by using this function:-