English 中文(简体)
Is the ASIHTTPRequest is not asynchronous?
原标题:

I am using ASIHTTPRequest to fetch some data from a web service.

I am making requests using a loop.

The problem is that it doesn t seem the request is going asynchronously so that my activityindicator is not working .

Is it true that ASIHTTPRequest is not asynchronous .

or should i use the regular nsmutablerequest to perform asynchronous request .

最佳回答

You should put your request in a download queue, i.e.

ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:request];
[request release];    

Just

[request startAsynchronous]; 

runs the request on the UI thread, so you should try it with download queue.

问题回答

For Sync Synchronous

  NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
  ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  [request startSynchronous];
  NSError *error = [request error];
  if (!error) {
    NSString *response = [request responseString];
  }

Creating an asynchronous request

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

And there is lot of more options like Queue and many more

You can refer http://allseeing-i.com/ASIHTTPRequest/How-to-use





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签