2011-12-13 52 views

回答

2

ASINetworkQueue按照它们插入队列的顺序运行所有请求。它是先进先出(FIFO)系统。

如果你想确保它们都是一个接一个地运行而不是并行的,那么你可以将并发设置为1.队列将从第一个请求开始并逐个运行,直到它到达最后一个请求

ASINetworkQueue *networkQueue = [[ASINetworkQueue alloc] init]; 

// Here we add all our 10 requests, the order in which we add 
// them determines the order they will execute 

// Set the concurrency to 1 and fire off the queue 
[networkQueue setMaxConcurrentOperationCount:1]; 
[networkQueue go]; 
+0

请注意,ASIHTTPRequest没有积极开发了:http://allseeing-i.com/%5Brequest_release%5D – vikingosegundo 2011-12-14 00:52:09

2

检查AFNetworking因为不再维护ASIHTTPRequest。您可以使用它NSOperationQueue,其中有属性maxConcurrentOperationCount。如果将其设置为1:

将最大操作数设置为1会有效地为处理操作创建一个串行队列。

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://gowalla.com/users/mattt.json"]]; 
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
    NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]); 
} failure:nil]; 

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; 
[queue setMaxConcurrentOperationCount:1]; 
[queue addOperation:operation]; 
[queue addOperation:anotherOperation];