我需要发出多个 http 请求,但我需要等待请求的响应才能继续下一个,但我不知道该怎么做。有没有人知道我怎么能不使用 dispatch_semaphore 做到这一点
这是我的代码:
-(void)multipleReques:(NSArray*)arrayUrl
{
__block NSInteger *countFailures = 0;
for (NSString *urlStr in arrayUrl)
{
NSURL *URL = [NSURL URLWithString:urlStr];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
if (error)
{
countFailures++;
}
}];
[task resume];
}
}
我会非常感谢你的帮助。