嗨,在我的应用程序中,我的图像每天都会根据日期更改,现在我想为用户提供下载选项,就像他们必须通过单击按钮下载一样,他们可以在设备中看到。我正在寻找很长时间来完成这项任务,但无法获得正确的解决方案,请告诉我如何实现这一目标。
我的 ImageView 代码。
- (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] ]]];
}
我现在已经使用上面的方法来显示图像,希望用户通过单击下载按钮将图像下载到设备的本地存储,请告诉我如何实现这一点。
谢谢。