简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM