【问题标题】:Pause and Resume download of big files from CDN (content distribution network) with dynamic url使用动态 url 暂停和恢复从 CDN(内容分发网络)下载大文件
【发布时间】:2015-07-15 23:35:05
【问题描述】:

我正在使用此代码通过 AFNetworking 下载文件:

NSURLRequest *fileUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"url file"]];
NSURLSessionDownloadTask *downloadTask;

downloadTask = [self downloadTaskWithRequest:fileUrl 
                     progress:nil
                  destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
                       //Return destination path
          } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
                       //Unzipping file.. etc..                
          }];

//start and resume download
[downloadTask resume];

//pause download
[downloadTask suspend];

此代码在暂停和恢复下载时运行良好,但服务器已更改为使用 CDN,并且文件的 URL 现在是动态的。

AFNetworking 的下载可以使用动态网址吗?

谢谢。

【问题讨论】:

  • 是的,它应该在内部处理。它会工作
  • 我的错误,我忘了告诉CDN何时开始工作并且URL开始改变,我无法继续已经开始的下载,总是从头开始。

标签: ios objective-c afnetworking


【解决方案1】:

我不能只使用 AFNetworking,而是根据需要添加 AFDownloadRequestOperation 库工作。

//Set download operation
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:"requestURL"
                                                                                 targetPath:"toPath"
                                                                               shouldResume:YES];

//Success and Failure callbacks
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    //completion
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //error
}];

//to resume download
[operation resume];

//to pause download
[operation pause];

【讨论】:

    猜你喜欢
    • 2021-07-07
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多