Save Image metadata PHPhotoLibrary vs ALAssetsLibrary

642 Views Asked by At

When using ALAssetsLibrary, I used to save image to photo library with proper exif using the code below:

        NSInteger orientation = 2;// Or whatever
        NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];

CMSetAttachment(imageDataSampleBuffer, kCGImagePropertyOrientation,
                [NSNumber numberWithInt: orientation],
                kCMAttachmentMode_ShouldPropagate);

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate);

    [library writeImageDataToSavedPhotosAlbum:jpegData metadata:(id)attachments completionBlock:^(NSURL *assetURL, NSError *error) {
          ...
          ...
     }

It's not clear how to translate that code when using PHPhotoLibrary. Can anyone provide the right way to save attachments along with the jpeg image?

1

There are 1 best solutions below

0
holtmann On

Use ImageIO to add Metadata to your JPEG/PNG image as described in the following article: Save the exif metadata using the new PHPhotoLibrary