zoukankan      html  css  js  c++  java
  • 利用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];
    }
  • 相关阅读:
    java栈的实现复习
    条件判断语句--linux
    转义符&脚本参数--linux
    linux备份脚本-模板
    github的搜索使用技巧
    sonarqube7.9安装部署(linux)
    openjdk与oraclejdk下载
    gitlab重写历史,清理历史大文件
    nexus私服搭建过程
    nexus私服关联本地maven配置
  • 原文地址:https://www.cnblogs.com/appshan/p/4569308.html
Copyright © 2011-2022 走看看