• 利用NSURLSession在网络里下载视频


    - (IBAction)StartDownLoad:(UIButton *)sender {
        
        //NSString *urlstr = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        NSString *urlstr= @"http://www.letv.com/ptv/vplay/22929585.html?vfm=bdvppzq&bl=hb#frp=v.baidu.com%2Fshow_intro%2F";
        urlstr = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        NSURL *url = [NSURL URLWithString:urlstr];
        
        
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
        
        NSURLSession * session = [NSURLSession sessionWithConfiguration:config];
        
      NSURLSessionDownloadTask * task =  [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
          NSHTTPURLResponse *httpresponse =(NSHTTPURLResponse*)response;
          if (httpresponse.statusCode==200) {
              
             // NSLog(@"%@",location);
              
            NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
              NSString *filepath = [path stringByAppendingPathComponent:@"down.mp4"];
              
              [[NSFileManager defaultManager]moveItemAtPath:[location path ]toPath:filepath error:Nil];
              
              NSLog(@"%@",filepath);
          }
          
        }];
        
        [task resume];
    }
  • 相关阅读:
    Elasticsearch 快速入门
    Linux 非互联网环境安装依赖包
    linux 安装mysql(rpm文件安装)
    Nginx安装与配置文件nginx.conf详解
    Linux 知识
    MySQL Windows安装连接
    post请求body格式
    MySQL 数据库备份
    SOAP与restful webservice
    大数据架构工具hadoop
  • 原文地址:https://www.cnblogs.com/appshan/p/4569308.html
Copyright © 2020-2023  润新知