Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save image in camera roll and get asset url

for an app I'm developing, I use UIImagePickerController to shoot a picture and store it in camera roll:

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
//... some stuff ...

        UIImageWriteToSavedPhotosAlbum([info objectForKey:@"UIImagePickerControllerOriginalImage"], nil, nil, nil);

}

the image is saved, now I need to get its reference url so I try to enumerate camera roll and get the last image, but I always get the image before the one I just shot.

Anybody has an idea how to get the reference of the just saved picture?

Thanks, Max

like image 952
masgar Avatar asked Jan 23 '13 20:01

masgar


1 Answers

This solution should fix the problem:

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeImageToSavedPhotosAlbum:((UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage]).CGImage
                                 metadata:[info objectForKey:UIImagePickerControllerMediaMetadata]
                          completionBlock:^(NSURL *assetURL, NSError *error) {
                              NSLog(@"assetURL %@", assetURL);
                          }];

et voila:

assetURL assets-library://asset/asset.JPG?id=1611E84C-24E2-4177-B49A-1C57B4A9C665&ext=JPG
like image 60
masgar Avatar answered Nov 17 '22 16:11

masgar