我正在使用此代码下载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下载是否可以使用动态网址?
感谢。
答案 0 :(得分:0)
我不能只使用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];