I want to use AFNetworking with a batch operation. I want to download 3 json files.
How to add basic authentication with AFHTTPRequestOperation ?
NSMutableArray *mutableOperations = [NSMutableArray array];
for (NSString *fileURL in filesToDownload) {
NSURLRequest *request = [NSURLRequest
requestWithURL:[NSURL URLWithString:fileURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation
, id responseObject) {
NSLog(@"success: %@", operation.responseString);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", operation.responseString);
}];
[mutableOperations addObject:operation];
}
NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:mutableOperations
progressBlock:^(NSUInteger numberOfFinishedOperations
, NSUInteger totalNumberOfOperations) {
NSLog(@"%d of %d complete", numberOfFinishedOperations, totalNumberOfOperations);
} completionBlock:^(NSArray *operations) {
NSLog(@"All operations in batch complete");
}];
[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO];
Thank you very much