Stella
Stella

Reputation: 1868

Saving image in iOS photo album(my folder) and have the image url stored

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) {

    }];

});

Upvotes: 1

Views: 2620

Answers (1)

Dennis
Dennis

Reputation: 2175

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.

Upvotes: 0

Related Questions