我有一个array
,其中包含不同的网址。我想用进度条下载一个文件,而不是启动下一个文件等等。使用网络交友一次下载一个文件
这是我到目前为止的代码;
-(void) func:(NSArray *) arry
{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.timeoutIntervalForRequest = 900;
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSMutableArray * downloadedUrl = [[NSMutableArray alloc] init];
for (NSString * str in arry) {
NSURL *URL = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL (NSURL targetPath, NSURLResponse response) {
NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
return [tmpDirURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse response, NSURL filePath, NSError *error) {
if(error)
{
NSLog(@"File Not Dowloaded %@",error);
}
}];
[downloadTask resume];
}
}
你将如何一次下载一个文件与进度条,然后从数组中删除url?
即使在文件下载失败的错误下,您应该继续处理下一个下载并处理失败的情况。 – 2016-06-21 10:21:28
现在可以......... :) –
如何计算进度。 @NiravDoctorwala – salmancs43