ryan_le
ryan_le

Reputation: 69

Download an image from URL and store in device (can be Photos folder in iPod), NOT IN APPLICATION

I have an issue about downloading image from URL. After checking, I realized that I could download and stored image into application (connect iPod to MAC and open this application, I can find this image which has just downloaded from server), but this image hasn't appeared in Photos folder of device (my iPod). Following is my code:

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg"]];
    [NSURLConnection connectionWithRequest:request delegate:self];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"pkm.jpg"];
    NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg"]];
    [thedata writeToFile:localFilePath atomically:YES];

Main task of my application is to download an image from server (via URL) and store image into Photo folder (or other folder that I can create), after that I use this image to set background for iPod.

Has anyone ever seen this case ? Please give me any ideas to resolve this issue.

Thanks anyway,

Ryan.

Upvotes: 0

Views: 494

Answers (1)

rckoenes
rckoenes

Reputation: 69459

You will need to save the image to the photo album, you can use the ALAssetsLibrary classes for this. They might be a bit more steep to learn but very powerful.

Or use the very easy: UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); method. This will just save the image to the Photo library.

Upvotes: 1

Related Questions