ShareKit/ShareKit — Issue #252: 'Save to Photo Album' does not allow the metadata to be saved
Author: demoend
Created: 2012-02-24 04:39:36+00:00
State: open

When using the 'Save to Photo Album' sharer, there is no way to save the metadata with the image.

Below is the code I used to fix the issue in my local copy of share kit. Could someone consider adding something similar so other users can save the metadata with the photo??

Thanks,
Brian.

- (void) writeImageToAlbum
{

NSData* imageData = [[NSData alloc] initWithContentsOfURL:item.URL];
UIImage* image = [UIImage imageWithData:imageData];

NSDictionary* metadata = [self extractExifFrom:imageData];

ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary writeImageToSavedPhotosAlbum:image.CGImage metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error)
{

if (error == nil)
{
[[SHKActivityIndicator currentIndicator] displayCompleted:SHKLocalizedString(@"Saved!")];
}

}];

}

-(NSDictionary*)extractExifFrom :(NSData*) imageData
{
NSDictionary* dic = nil;

CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);

if ( NULL == source )
{
//Unable to read data
}
else
{
CFDictionaryRef metadataRef =
CGImageSourceCopyPropertiesAtIndex ( source, 0, NULL );
if ( metadataRef )
{
NSDictionary* immutableMetadata = (NSDictionary *)metadataRef;
if ( immutableMetadata )
{
dic =
[ NSDictionary dictionaryWithDictionary : (NSDictionary *)metadataRef ];
}

CFRelease ( metadataRef );
}

CFRelease(source);
source = nil;
}

return dic;
}