阿神2017-04-18 09:16:58
You can download it through Group, use dispath_group_enter() and dispath_group_leave() to put the thread into the group, use dispath_group_notify to monitor whether the task has been downloaded, do not use dispath_group_wait to monitor, because dispath_group_wait will block the thread.
I wrote an example below:
NSString *urlStr1 = @"url1";
NSString *urlStr2 = @"url2";
NSString *urlStr3 = @"url3";
NSArray *urlStrings = @[urlStr1, urlStr2, urlStr3];
dispath_group_t requestGroup = dispath_group_create();
for(NSString urlString in urlStrings) {
dispatch_group_enter(requestGroup);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
dispatch_group_leave(requestGroup);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
dispatch_group_leave(requestGroup);
}];
}
dispatch_group_notify(requestGroup, dispatch_get_main_queue(), ^{
//doSomething
});
I did it with all my hands, I hope I can give you a good review^_^
This method seems a bit troublesome, if any master has a better method, I hope to share it