I am using ALAssetsLibrary to list details of photos present in cameraroll. But how to get details of a particular selected photo from cameraroll using ALAssetsLibrary?
Assume i selected ABC.jpeg from cameraroll. I want to display the exif details of only ABC.jpeg. Not exif details of other photos present in cameraroll.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.imageView.image = image;
NSLog(@"image %@\ninfo: %@",image, info);
[picker dismissViewControllerAnimated:YES completion:NULL];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
if (asset){
NSDictionary *data = [[asset defaultRepresentation] metadata];
NSLog(@"%@",data);
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
ok here is the code how to get the asset of a media picker with the image picker:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.imageView.image = image;
NSLog(@"media image info: %@", info);
//use assetLib
NSURL *imageURL = [info objectForKey:UIImagePickerControllerReferenceURL];
if(imageURL) {
[self getPictureInfoFromAssetURL:imageURL
success:^(NSDictionary*)alInfo {
NSLog(@"asset lib image info: %@", alInfo);
} failure:^(NSError *error) {
NSLog(@"error reading asset lib image info: %@", error);
}];
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)getPictureInfoFromAssetURL:(NSURL *)url
success:(void (^)(NSDictionary *alInfo))success
failure:(void (^)(NSError *error))failure {
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock: ^(ALAsset *myasset) {
ALAssetRepresentation *rep = [myasset defaultRepresentation];
if(success {
success([rep metadata]);
}
failureBlock: ^(NSError *err) {
if (failure) {
failure(err);
}
}];
}