@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//这部分是讲data数据进行归档和解归档来下载图片
NSString *path = @"http://image.game.uc.cn/2014/8/1/9833190.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *imageData = [NSData dataWithContentsOfURL:url];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:imageData];
NSData *data2 = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[data2 writeToFile:@"/Users/gaozhenyusky/Desktop/image3.jpg" atomically:YES];
//这部分是直接来下载图片
NSURL *url2 = [NSURL URLWithString:@"http://image.game.uc.cn/2014/8/1/9833190.jpg"];
NSData *data3 = [NSData dataWithContentsOfURL:url2];
[data3 writeToFile:@"/Users/gaozhenyusky/Desktop/image2.jpg" atomically:YES];
}
xcode如何下载图片!
最新推荐文章于 2024-03-13 22:26:50 发布