ASIHttpFormDataRequest 结束时通知
我如何知道 ASIHttpFormDataRequest 何时结束? 实际上我正在连续做其中两个。第一个包括发送消息,而另一个包括从数据库检索所有消息。
或者有时会发生我的第一条消息尚未发送而我的第二个请求只是给我未上传的消息列表。
我想在第一个任务结束后推迟第二个任务。 谢谢 !
有什么想法吗?
谢谢 :)
How can I know when my ASIHttpFormDataRequest ends ?
Actually I am doing two of them in a row. The first one consist in sending a message while the other one consist in retrieving all the messages from a database.
Or it happens sometimes that my first message has not been sent yet and my second request just give me the unuploaded list of messages.
I would like to delay the second one at the end of the first one.
Thanks !
Any ideas ?
Thank you :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异步使用请求是一个很好的做法。
要查明请求是否已完成,您只需使您的类符合
[ASIHTTPRequestDelegate][1]
即可。它为您提供了一系列方法来实现成功、失败或重定向的请求。
在给定的情况下,您正在寻找
- (void)requestFinished:(ASIHTTPRequest *)request;
您必须将请求的委托设置为当前调用类。
根据当前请求的结果,您可以触发另一个请求。您可以在其中放置一个
if-statement
来检查 URL 和响应代码并相应地触发下一个请求。 (还有许多其他方法可以确定何时可以调用下一个请求。但最简单的方法是监听第一个请求的结果。)以下是 ASIHTTPRequest 项目文档:
HTH
It is a good practice to use requests asynchronously.
To find out if a request has finished or not, you could do this by simply conforming your class to the
[ASIHTTPRequestDelegate][1]
.It gives you a bunch of methods to implement for a successful, failed or a redirected request.
In the given case you're looking for
- (void)requestFinished:(ASIHTTPRequest *)request;
You would have to set the delegate of the request to the current calling class.
Depending on the result of your current request you may then fire another request. You could put an
if-statement
in there to check the URL and the response code and fire your next request accordingly. (There are many other ways to determine when you could call the next request. But the easiest would be to listen to the result of the first request.)Here's a bit of code from the ASIHTTPRequest Projects Documentation:
HTH