I'm struggling to implement download mechanism for multiple files using AFNetworking. I want to download zip file one after another from multiple url with progression message. I tried like following code, but getting error as -
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSOperationQueue addOperation:]: operation is already enqueued on a queue'
Here is my code portion :
- (void) downloadCarContents:(NSArray *)urlArray forContent:(NSArray *)contentPaths {
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
for (int i=0; i< urlArray.count; i++) {
NSString *destinationPath = [self.documentDirectory getDownloadContentPath:contentPaths[i]];
NSLog(@"Dest : %@", destinationPath);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *operation = [manager GET:urlArray[i]
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error : %ld", (long)error.code);
}];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:destinationPath append:NO];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float percentage = (float) (totalBytesRead * 100) / totalBytesExpectedToRead;
[self.delegate downloadProgression:percentage];
}];
[operationQueue addOperation:operation];
}
}
Please help.