美文网首页
下载网络视频到沙盒

下载网络视频到沙盒

作者: guoguojianshu | 来源:发表于2019-11-07 22:56 被阅读0次
    //沙盒的路径
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        
        
        AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
        //沙盒的全路径
        NSString  *fullPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"test11.mov"];
        NSURL *url = [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-smallvideo-transcode/20985849_722f981a5ce0fc6d2a5a4f40cb0327a5_3.mp4"];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //targetPath为目标路径
     NSURLSessionDownloadTask *task =
        [manager downloadTaskWithRequest:request
                                progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    //返回的是全路径
                                    return [NSURL fileURLWithPath:fullPath];
                                }
                       completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {   
                           //filePath就是文件路径
                       }];
        [task resume];

    相关文章

      网友评论

          本文标题:下载网络视频到沙盒

          本文链接:https://www.haomeiwen.com/subject/hcpbbctx.html