Search code examples
iphoneimagecamerauiimagepickercontrollerphotos

Can I save an image to a specific album with the camera roll when saving via writeImageToSavedPhotosAlbum:metadata:completionBlock:?


I have an app that edits a photo's exif data then saves that image to the camera roll via:

[library writeImageToSavedPhotosAlbum:[newTestImage CGImage] metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
    //error
}];

This works fine, but is there a way that I can save the image to a specific (ideally new) album within the camera roll? I have searched extensively here and elsewhere and I'm aware of addAssetsGroupAlbumWithName: but as that won't add the new image metadata I don't think I can use it.

Thanks for any help.


Solution

  • There is a great category out there that helps you easily save a photo to a custom album.

    Here it is on GitHub

    https://github.com/Kjuly/ALAssetsLibrary-CustomPhotoAlbum

    You'll need to make some adjustments to support saving the metadata as well, but it should be as simple as replacing the above code's use of

    - (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock
    

    and using this instead after passing in the metadata

    - (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef metadata:(NSDictionary *)metadata completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock