0

Using the

MFMailComposeViewController

and attaching an image with GPS coords (taken on the iOS device with camera) like:

UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData* data = UIImageJPEGRepresentation(image, 1.0);
[self.mailer addAttachmentData:data mimeType:@"image/jpeg" fileName:@"testimagesent.jpg"];

is not "including" the GPS data with the email send.

But, if the same file is sent using the iOS email application the GPS information is being sent.

Any clue on why this is happening and / or a way to fix this, setting on the MFMail, ???

[Addition]

After playing around with this a bit, if the image is part of the main bundle of the app, the metadata is included with the image on the email attachment.

NSString *photoFilePath = [[NSBundle mainBundle] pathForResource:@"testimage" ofType:@"jpg"];
NSData *data = [NSData dataWithContentsOfFile:photoFilePath];
[self.mailer addAttachmentData:data mimeType:@"image/jpeg" fileName:@"testimagesent.jpg"];

If the image is not part of the main bundle (from photopicker, etc) the data is not part of the attachment.

Will be playing arounds a bit, but this is looking like some sort of Apple privacy issue on sending a photo via an application email?

[Addition2]

It looks like it is boiling down to the statement

CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) metadataAsMutable);

Is not adding the metadata if the image is from the library. This is strange and not accepted 100%, but the code looks good and is adding / changing for a bundled image file.

ort11
  • 3,359
  • 4
  • 36
  • 69
  • 1
    This would be my guess, though I am not 100% sure as I haven't tried to keep the GPS data is this situation. When you encode the image as a JPEG the GPS data is not getting encoded or the original UIImage doesn't have the GPS data encoded in it. One of those two is just image data without GPS data. It probably isn't MFMailComposeViewController. – Stephen Johnson Dec 24 '13 at 17:00
  • Stephen is correct. EXIF data is added only when you save the image to the library. It is not present with `UIImagePickerControllerOriginalImage` – Rok Jarc Dec 24 '13 at 17:06
  • This might help at least to get started: http://stackoverflow.com/a/5294574/653513 – Rok Jarc Dec 24 '13 at 17:07
  • Thanks for the info, please see addition on the question – ort11 Dec 26 '13 at 14:08

2 Answers2

0

The UIImage object contains only image data, not EXIF meta data (such as GPS coordinates).

However, it's my understanding that the "info" dictionary in your code above contains additional keys that can be used to access the metadata.

Take a look at this blog entry for more information: http://blog.codecropper.com/2011/05/getting-metadata-from-images-on-ios/

Tron5000
  • 844
  • 11
  • 24
0

https://github.com/ort11/iOSImageMetadataRoutinesThere were / are some special code flows that looks like have to be addressed

  1. If resizing the photo and / or get from photo library, may loose metadata before emailing the photo

Solution is to get the photo from the library, get the metadata from file, resize the photo, store the file local to the app, then add back in the metadata, then attach for email.

  1. If taking a photo in the app, may not have meta data at all before emailing the photo

Solution is to take the photo, build date and time (and / or other) metadata, store the photo locally, add metadata to the file, then attach to email.

Geesh

https://github.com/ort11/iOSImageMetadataRoutines

ort11
  • 3,359
  • 4
  • 36
  • 69