ASIHttpFormDataRequest 结束时通知

发布于 2024-12-03 20:07:09 字数 195 浏览 1 评论 0原文

我如何知道 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 技术交流群。

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

发布评论

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

评论(1

北凤男飞 2024-12-10 20:07:09

异步使用请求是一个很好的做法。

要查明请求是否已完成,您只需使您的类符合 [ASIHTTPRequestDelegate][1] 即可。
它为您提供了一系列方法来实现成功、失败或重定向的请求。

在给定的情况下,您正在寻找
- (void)requestFinished:(ASIHTTPRequest *)request;
您必须将请求的委托设置为当前调用类。

根据当前请求的结果,您可以触发另一个请求。您可以在其中放置一个 if-statement 来检查 URL 和响应代码并相应地触发下一个请求。 (还有许多其他方法可以确定何时可以调用下一个请求。但最简单的方法是监听第一个请求的结果。)

以下是 ASIHTTPRequest 项目文档

- (IBAction)grabURLInBackground:(id)sender
{
   NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
   // Use when fetching text data
   NSString *responseString = [request responseString];

   // Use when fetching binary data
   NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}

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:

- (IBAction)grabURLInBackground:(id)sender
{
   NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
   // Use when fetching text data
   NSString *responseString = [request responseString];

   // Use when fetching binary data
   NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}

HTH

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