1

I want to save an image (which is downloaded from server) in iOS device photo album and store that image photo album url in local database. My question is, How do i get that photo album image url after saving the image?

I am able to save the image in photo album using the following ALAsset code: But, I need this url image also to be stored in my local db. So next time, i won't download the same image from server and i can load directly from device photo album.

[self.maAssetsLibrary saveImage:image
                          toAlbum:@"My-Album"
                       completion:completion
                          failure:nil];

Please suggest.

UPDATE: I tried this, but NOT getting me the photo album image URL after saving the image.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    // The completion block to be executed after image taking action process done
    void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
    };

    [self.maAssetsLibrary saveImage:image toAlbum:@"My-Album" completion:^(NSURL *assetURL, NSError *error){
        if (error) {
            NSLog(@"error");
        } else {
            NSLog(@"url %@", assetURL);
        }
    } failure:^(NSError *error) {

    }];

});

Stella
  • 1,728
  • 5
  • 41
  • 95
  • possible duplicate of [iPhone: How do I get the file path of an image saved with UIImageWriteToSavedPhotosAlbum()?](http://stackoverflow.com/questions/4457904/iphone-how-do-i-get-the-file-path-of-an-image-saved-with-uiimagewritetosavedpho) – CRDave Mar 12 '15 at 09:20
  • 1
    I don't think you can access to URL of the image in the photo album. However, you can save it in your application's folder (Like documents), use that URL while also saving it to the photo album. – Lord Zsolt Mar 12 '15 at 09:20
  • I will not suggest to do that. iOS photo album is for use not for Application. You should not save image in Photo Album till user don't tell to do that. If you want to save image for faster load than you should use Image Caching. If you want to save it for longer user you should manually save in Data Container (Application File System). – CRDave Mar 12 '15 at 09:25
  • @LordZsolt: You can get the asset url of photo – Midhun MP Mar 12 '15 at 09:32
  • Hi Midhun, Another problem would arrive for me is, I need to save this image in My-Album folder. If i use writeImageToSavedPhotosAlbum, how can i store image in My-Album folder? Any help please? – Stella Mar 12 '15 at 09:42

1 Answers1

0

Due to sandboxing you can't get such a url. As @Lord Zsolt proposes in the comment, you can overcome this by saving images in your application's folder. In this case you might e.g. give them a name that serves as key to identify each image.

EDIT

As @MidhunMP commented, I was wrong on that! There is a way (and I'm happy to know that now) and it comes from this Stack Overflow answer, provided by @CRDave in the comment above.

The main point is to use ALAssetsLibrary's writeImageToSavedPhotosAlbum:orientation:completionBlock: method.

It's always nice to learn.

Community
  • 1
  • 1
Dennis
  • 2,119
  • 20
  • 29
  • This answer is wrong, we can get the asset url of images and can load images using that asset url. – Midhun MP Mar 12 '15 at 09:32
  • @MidhunMP Can you show how? I would be the first to be interested. – Dennis Mar 12 '15 at 09:34
  • 1
    Check the link added by CRDave as comment below the question. Through that way you can get the URL – Midhun MP Mar 12 '15 at 09:36
  • Hi Midhun, Another problem would arrive for me is, I need to save this image in My-Album folder. If i use writeImageToSavedPhotosAlbum, how can i store image in My-Album folder? Any help please? – Stella Mar 12 '15 at 09:43
  • 1
    @Stella: Check this thread, you will get the answer here : http://stackoverflow.com/questions/11972185/ios-save-photo-in-an-app-specific-album and here: http://stackoverflow.com/questions/10954380/save-photos-to-custom-album-in-iphones-photo-library – Midhun MP Mar 12 '15 at 09:49
  • I tried this, but not solving this problem still. Please check my question updated. – Stella Mar 12 '15 at 13:07