Reda
Reda

Reputation: 1335

Get photo file with metadata from album photo

It is possible to retrieve photo file from the album photo with metadata (IPTC)?
I've tried UIImagePickerController to get UIImage and when I save it to a file, it doesn't contain any metadata information.
There is a way to get the original photo file with ALAsset library?

Upvotes: 0

Views: 547

Answers (1)

Reda
Reda

Reputation: 1335

I found a solution with AssetsLibrary:

- (void)savePhoto:(NSURL*) url <br
{
    NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
    [assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
        NSString* originalFileName = [[asset defaultRepresentation] filename];
        NSString *path = [applicationDocumentsDir stringByAppendingPathComponent:originalFileName];
        ALAssetRepresentation *rep = [asset defaultRepresentation];
        Byte *buffer = (Byte*)malloc(rep.size);
        NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
        NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
        //NSLog(@"%@",data);
        [data writeToFile:path atomically:YES];
    } failureBlock:^(NSError *err) {
        NSLog(@"Error: %@",[err localizedDescription]);
    }];
}

Upvotes: 1

Related Questions