ASINetworkQueue是否支持多个requestDidFinishSelector?

发布于 2024-12-02 09:18:21 字数 987 浏览 1 评论 0原文

在视图控制器中,我有多种具有不同 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜血缘 2024-12-09 09:18:21

使用 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文