2
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://twitter.com"]];

NSURL *url = [NSURL URLWithString:@"https://alpha-api.app.net/stream/0/posts/stream/global"];
NSURLRequest *r = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:r success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"App.net Global Stream: %@", JSON);
} failure:nil];
AFJSONRequestOperation *operation1 = [AFJSONRequestOperation JSONRequestOperationWithRequest:r success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"App.net Global Stream: %@", JSON);
} failure:nil];

[client enqueueBatchOfHTTPRequestOperations:@[operation, operation1] progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {

} completionBlock:^(NSArray *operations) {
    NSLog(@"%@", operations);
}];

enqueueBatchOfHTTPRequestOperations 在 operation 和 operation1 阻塞之前触发完成。

确实阅读了https://github.com/AFNetworking/AFNetworking/issues/362并尝试使用 dispatch_group 进行可能的修复,但它仍然无法正常工作。

4

1 回答 1

1

更改您的代码以使用 AFHTTPRequestOperation 而不是 AFJSONRequestOperation 并使用 NSJSONSerialization 手动解析 JSON,您会发现在所有操作都按要求完成后触发队列完成块。

于 2013-07-24T22:12:07.893 回答