2013-04-18 74 views
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完成在操作和operation1塊之前觸發。在調用完所有AFJSONRequestOperation完成之前,AFNetworking enqueRequestOperations觸發完成

沒有閱讀https://github.com/AFNetworking/AFNetworking/issues/362並嘗試使用dispatch_group進行修復,但它仍然無效。

回答

1

將您的代碼更改爲使用AFHTTPRequestOperation而不是AFJSONRequestOperation,並使用NSJSONSerialization手動解析JSON,並在所有操作完成後根據需要啓動您的隊列完成塊。

相關問題