开发者

Does ASINetworkQueue support multiple requestDidFinishSelectors?

开发者 https://www.devze.com 2023-04-02 12:22 出处:网络
In a view controller, I have multiple methods with different ASIFormDataRequests which have different finishSelectors.so methodA -> finishselector(AFinished:), methodB ->finishselector(BFinished:), an

In a view controller, I have multiple methods with different ASIFormDataRequests which have different finishSelectors. so methodA -> finishselector(AFinished:), methodB ->finishselector(BFinished:), and methodC ->finishselector(CFinished:)

I have a 1 method which handles all requests as shown below:

-(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];
}

I noticed that when I sent requests 开发者_运维技巧for method A->B->C and B finished before A, then BFinished: would be called twice, first with data corresponding to method B, then data corresponding to method A. Does ASINetworkQueue only handle 1 finishSelector at a time? would i need to separate networkqueues for each method?

Thanks


Requests fired with the ASINetworkQueue still fires their setCompletionBlock on request completion. The completion blocks execute before the queue's selector for requestFinished. See this blog for a tutorial:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号