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];
    }
  • 相关阅读:
    逆向
    BUUCTF
    学校健康系统自动打卡
    SQL数据库操作练习(3)
    简单尝试UPX脱壳
    网站WAF-安全狗的绕过(一)
    【题解】担心
    【题解】树上的鼠
    【题解】CF1299B Aerodynamic
    【题解】等你哈苏德
  • 原文地址:https://www.cnblogs.com/appshan/p/4569308.html
Copyright © 2011-2022 走看看