我有一个应用程序,我想将来自在线图像路径(url)的图标图像存储在本地。
当用户访问另一个 url 时,我将此图像存储在本地,该图标正在替换为以前的图标,以及如何替换此图标以重复使用,请帮助我。
谢谢你!
NSString *strImage = [NSString stringWithFormat:@"%@",aBook.image];
NSURL *url4Image = [NSURL URLWithString:strImage];
NSData *data = [NSData dataWithContentsOfURL:url4Image];
if(data !=NULL)
{
imageView =[[UIImage alloc] initWithData:data];
if(imageView == NULL)
{
imageView =[UIImage imageNamed:@"dealsbell_lo.png"]; // NoImage.png
}
}
NSData *imageData = UIImagePNGRepresentation(imageView);
NSString *imageName = [NSString stringWithFormat:@"image.png"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:YES];
cell.imageView.image = imageView;