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);
}];在操作和operation1阻塞之前触发enqueueBatchOfHTTPRequestOperations完成。
我读了https://github.com/AFNetworking/AFNetworking/issues/362,并尝试了用dispatch_group修复,但仍然不起作用。
发布于 2013-07-25 06:12:08
将您的代码更改为使用AFHTTPRequestOperation而不是AFJSONRequestOperation,并使用NSJSONSerialization手动解析JSON,您将发现队列完成块在所有操作按需完成后触发。
https://stackoverflow.com/questions/16086051
复制相似问题