美文网首页
视频下载

视频下载

作者: 小木虫666 | 来源:发表于2023-05-05 11:09 被阅读0次
+ (void)downloadVideoWithUrl:(NSString *)videoUrl
                    progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock
           completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler
{
    NSParameterAssert(videoUrl);
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSURL *url = [NSURL URLWithString:videoUrl];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    NSURLSessionDownloadTask *download = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
      
    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
        return [self videoUrlWithPath:response.suggestedFilename];
        
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        if (completionHandler) {
            completionHandler(response,filePath,error);
        }
    }];
    
    [download resume];
}

+ (NSURL *)videoUrlWithPath:(NSString *)component
{
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:component];
    return [NSURL fileURLWithPath:path];
}

相关文章

网友评论

      本文标题:视频下载

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