繁体   English   中英

从URL下载图像并存储在设备中(可以是iPod中的Photos文件夹),而不是应用程序中

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

我有一个关于从URL下载图像的问题。 检查后,我意识到可以下载图像并将其存储到应用程序中(将iPod连接到MAC并打开该应用程序,我可以找到刚刚从服务器下载的图像),但是该图像未出现在设备的Photos文件夹中(我的iPod)。 以下是我的代码:

    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];

我的应用程序的主要任务是从服务器(通过URL)下载图像并将图像存储到Photo文件夹(或我可以创建的其他文件夹)中,然后使用该图像设置iPod的背景。

有人见过这种情况吗? 请给我任何解决此问题的想法。

不管怎么说,还是要谢谢你,

瑞安

您将需要将图像保存到相册,您可以为此使用ALAssetsLibrary类。 他们可能学起来有些陡峭,但功能非常强大。

或使用非常简单的方法: UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); 方法。 这只会将图像保存到照片库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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