Get ReferenceURL after saving the image using UIImageWriteToSavedPhotosAlbum ()

I want to get referenceURL for the image that I saved in the camera roll using UIImageWriteToSavedPhotosAlbum (). iOS 4.1 or higher can easily do this with 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 can not find a reasonable way in the case of earlier iOS, where the only way to save the image in the camera library is UIImageWriteToSavedPhotosAlbum (). One of the ways I'm thinking of is to search for a saved image using ALAssetsGroup, etc. This is not very convenient for me, and it only helps iOS 4.0.

Thanks in advance,

Kiyo

+5
source share
1 answer

writeImageToSavedPhotosAlbum:

[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 
    }  
}];  
+2

All Articles