ASINetworkQueue是否支持多个requestDidFinishSelectors?

时间:2011-09-02 08:45:10

标签: objective-c cocoa-touch selector network-protocols

在视图控制器中,我有多个具有不同的ASIFormDataRequests的方法,这些方法具有不同的finishSelectors。方法A - > finishselector(AFinished :),methodB - > finishselector(BFinished :)和methodC - > finishselector(CFinished :)

我有一个处理所有请求的方法,如下所示:

-(void)sendRequest:(NSURL *)url withParams:(NSDictionary *)params andSelector:(NSString *)selector
{
NSString *jsonString = [params yajl_JSONString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:jsonString forKey:@"json"];
[request setTimeOutSeconds:15];
[[self networkQueue] setDelegate:self];
[[self networkQueue] setRequestDidFinishSelector:NSSelectorFromString(selector)];
[[self networkQueue] setRequestDidFailSelector:@selector(asiRequestFailed:)];
[[self networkQueue] addOperation:request];
[[self networkQueue] go];
}

我注意到当我发送方法A-> B-> C和B的请求在A之前完成时,则BFinished:将被调用两次,首先是数据对应于方法B,然后是对应于方法A的数据。 ASINetworkQueue一次只能处理1个finishSelector吗?我需要为每种方法分离网络队列吗?

由于

1 个答案:

答案 0 :(得分:0)

使用ASINetworkQueue触发的请求仍会在请求完成时触发其setCompletionBlock。完成块在requestFinished的队列选择器之前执行。有关教程,请参阅此博客:

http://ygamretuta.me/2011/09/20/manage-multiple-asynchronous-request-in-ios-with-asinetworkqueue/