ASINetworkQueue是否支持多个requestDidFinishSelector?
在视图控制器中,我有多种具有不同 ASIFormDataRequest 的方法,这些方法具有不同的 finishSelector。所以方法A-> finishselector(AFinished:)、methodB ->finishselector(BFinished:) 和 methodC ->finishselector(CFinished:)
我有一个处理所有请求的 1 方法,如下所示:
-(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 个完成选择器?我需要为每种方法分离网络队列吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ASINetworkQueue 触发的请求仍会在请求完成时触发其 setCompletionBlock。完成块在 requestFinished 的队列选择器之前执行。请参阅此博客以获取教程:
http ://ygamretuta.me/2011/09/20/manage-multiple-asynchronous-request-in-ios-with-asinetworkqueue/
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/