我正在循环中运行AFNetworking GET请求。 “codeArray”有8000个奇数元素。然而,AFNetworking仅发出约1000个请求并突然停止。谁知道问题可能是什么?有没有办法可以确保AFNetworking在不中断的情况下进行所有服务器调用?
for(NSString *station in codeArray)
{
[self getLocationForStation:station
success:^(NSDictionary *response) {
} fail:^{
}];
}
使用AFNEtworking进行GET调用的函数类似于
- (void)getLocationForStation:(NSString *)stationCode
success:(void (^)(NSDictionary *response))success fail: (void (^)())fail
{
NSString *urlString = [NSString stringWithFormat:@"http://myurl.in/station-details/%@.json", stationCode];
NSURL *url = [NSURL URLWithString:urlString];
url = [url URLByAppendingQueryString:[NSString stringWithFormat:@"_=%f", [[NSDate date] timeIntervalSince1970]]];
IRCTCHTTPRequestOperationManager *manager = [IRCTCHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:[url absoluteString] parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// NSLog(@"Failure!!");
}];
}
答案 0 :(得分:1)
糟糕! 8000是很多同时请求!那差不多超过了9000 !!!!我会限制你的请求,而不是弄清楚为什么你不能同时做8000。
幸运的是,NSOperationQueue使异步操作相对容易。这是一个很好的总结如何执行此操作的页面:Concurrent Operations Demystified