您的位置:首页 > 移动开发 > IOS开发

iOS 文件下载

2016-02-25 10:33 489 查看
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"路径"]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:60.0f];
// 开启线程
NSOperationQueue *queue=[[NSOperationQueue alloc] init];

// 发送异步get请求,结果通过block返回
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
// 沙盒路径
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"icon-integralCenter.png"];
// 写入沙盒
BOOL r = [data writeToFile:path atomically:YES];

if (r)
NSLog(@"保存图片成功");
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: