将映像下载到设备IOS7中的本地存储
嗨,在我的应用程序中,我有一个图像,它每天都随着日期而变化。现在,我想给用户提供下载选项,就像他们必须通过单击按钮下载一样,他们可以在那里看到设备。我正在寻找很长时间来完成这项任务,但无法得到适当的解决方案。请告诉我如何实现这项任务 我的ImageView代码将映像下载到设备IOS7中的本地存储,ios,imagedownload,Ios,Imagedownload,嗨,在我的应用程序中,我有一个图像,它每天都随着日期而变化。现在,我想给用户提供下载选项,就像他们必须通过单击按钮下载一样,他们可以在那里看到设备。我正在寻找很长时间来完成这项任务,但无法得到适当的解决方案。请告诉我如何实现这项任务 我的ImageView代码 - (void)viewDidLoad { [super viewDidLoad]; //this is url which gives the date has a echo NSMutableURLRe
- (void)viewDidLoad
{
[super viewDidLoad];
//this is url which gives the date has a echo
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"url"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
//This is for Response
// here I'm connecting the date to my url do display the image
NSString *imgstr=[NSString stringWithFormat:@"url",resSrt];
//assign your image view name
imageview.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",imgstr] ]]];
}
我已经用上面做了显示图像现在想用户下载图像通过点击下载按钮到本地存储的设备请告诉我如何实现这一点
谢谢。首先同步下载图像并保存在文档文件夹中,然后在图像视图上显示
NSURL *url = [NSURL URLWithString: @"url"];
NSString *imagePath = [DOCUMENTS_PATH stringByAppendingPathComponent:@"some name"];
NSError *error = nil;
NSData *imageData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error: &error];
if (!error) {
[imageData writeToFile:imagePath atomically:YES];
}
然后将此图像交给图像视图
imageview.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/some name", DOCUMENTS_PATH]];
是的,但下载完成后您应该分配此图像。但是我希望用户下载图像如果用户喜欢图像,他将下载其他图像我们不需要下载我想要那样我不想自动下载请告诉我如何做如果您使用您编写的其他代码,它也会下载,但会保存在缓存文件夹中。因此,我们最好下载并向用户展示。如果用户不想这样做,则从文档文件夹中删除是否存在创建文件夹和保存图像的任何可能性请参阅此链接以了解如何创建文件夹