- (void)viewDidLoad {
[super viewDidLoad];
[self downLoadImg];
}
- (void)downLoadImg {
NSString *urlString = @" url地址";
NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *cachePath = [cacheDir stringByAppendingPathComponent:@"imageName"];
if ([[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
UIImage *img = [UIImage imageWithContentsOfFile:cachePath];
return;
}
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSURL *url = [NSURL URLWithString:urlString];
NSData *dataImg = [NSData dataWithContentsOfURL:url];
[dataImg writeToFile:cachePath atomically:YES];
dispatch_async(dispatch_get_main_queue(), ^{
});
});
}