码迷,mamicode.com
首页 > 其他好文 > 详细

从网络上下载大文件(视频)

时间:2015-06-11 12:39:14      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
- (IBAction)getbigfile:(UIButton *)sender {
    NSString *str = @"http://b.hiphotos.baidu.com/video/pic/item/e850352ac65c1038698cd94eb7119313b17e894f.jpg";
    NSURL *url = [NSURL URLWithString:str];
    
    NSURLRequest * request = [[NSURLRequest alloc]initWithURL:url];
    
    NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
    [conn start];
    
}
View Code
技术分享
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
        self.receivedData = [[NSMutableData alloc]init];
    
    
}
View Code
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [self.receivedData appendData:data];
    NSLog(@"接受到服务器端来的数据%d",data.length);
 NSString *Data =[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
    NSLog(@"%@",Data);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

    NSLog(@"222");
    
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/a.mp4"];
    NSLog(@"string = %@",path);
    [self.receivedData writeToFile:path atomically:YES];
}

 

从网络上下载大文件(视频)

标签:

原文地址:http://www.cnblogs.com/appshan/p/4568584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!