Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain ReferenceURL after saving an image using UIImageWriteToSavedPhotosAlbum()

I want to obtain the referenceURL to the image that I saved into camera roll using UIImageWriteToSavedPhotosAlbum(). iOS 4.1 or above can do it easily by using AssetLibrary.

ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL* url, NSError* error) {
    if (error == nil) {
        savedURL = url;
    }
};    
UIImage * originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSMutableDictionary * metadata = (NSMutableDictionary *)[info objectForKey:UIImagePickerControllerMediaMetadata];  
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:originalImage.CGImage
                             metadata:metadata
                      completionBlock:completionBlock];

But, I cannot figure out a smart way in case of earlier iOS where the only way of saving an image to the camera library is UIImageWriteToSavedPhotosAlbum(). One way I think about is looking around the saved image using ALAssetsGroup etc. This is not smart for me, and it only helps iOS 4.0.

Thank you in advance,

Kiyo

like image 804
Kiyo Chinzei Avatar asked Nov 05 '22 15:11

Kiyo Chinzei


1 Answers

Use writeImageToSavedPhotosAlbum instead:

[library writeImageToSavedPhotosAlbum:[originalImage CGImage] orientation:(ALAssetOrientation)[originalImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  // oops, error !
    } else {  
        NSLog(@"url %@", assetURL);  // assetURL is the url you looking for 
    }  
}];  
like image 128
Ricardo Rivaldo Avatar answered Dec 05 '22 23:12

Ricardo Rivaldo