我有一個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