3

I used to save a photo to the camera roll using ALAssetLibrary's writeImageToSavedPhotosAlbum:metadata:completionBlock, but that is now deprecated in iOS 9.0, so I switched to PHPhotoLibrary's version which looks like

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    [PHAssetChangeRequest creationRequestForAssetFromImage:image];
}completionHandler:^(BOOL success, NSError *error) {
    if (success){
        NSLog(@"Image Saved!");
    } else {
        NSLog(@"Error: %@", error);
    }
}];

This saves the image itself, but loses the metadata (exif ect) and I can't find any fixes of how to preserve this data when I save the photo. Any help would be appreciated. TYIA

Mitch D
  • 79
  • 9
  • 1
    Been trying to figure out how to remove exif data without rewriting sources. This did it :) One man's problem is another man's solution. – Hanny Nov 18 '16 at 01:16

1 Answers1

4

I think the method

creationRequestForAssetFromImage:(UIImage *)image;

saves only image data. It doesn't include metadata.

If you want to save a image with metadata, you can do it by the following step.

First Save your image in temporary folder and get its path as NSURL. Then Call the method

creationRequestForAssetFromImageAtFileURL:(NSURL *)fileURL;

with the NSURL you get in First step.

M.Masa
  • 532
  • 4
  • 20
  • @MitchD Sorry. I don't know the exact code to do same things in Android. But it's possible, just save files on storage and register them on media store. – M.Masa Jul 10 '16 at 03:18
  • For iOS 9+, you can skip the intermediate file step and do `let request = PHAssetCreationRequest.forAsset()`, and then `request.addResource(with:data:options:)` using the image data you've added your metadata to, all within the PHPhotoLibrary `performChanges` block. – Undrea Apr 18 '17 at 16:07
  • @Undrea Thank you for your information. I will try your suggestion. – M.Masa Jul 05 '17 at 04:09
  • So is it possible to use `creationRequestForAssetFromImageAtFileURL:(NSURL *)fileURL;` that to write exif to a rendered uiimage? – Reza.Ab Jan 26 '18 at 02:46