How to cancel ASIFormDataRequest in iPhone

390 views Asked by At

How to cancel a ASIFormDataRequest using blocks?.

__block ASIFormDataRequest *req = [ASIFormDataRequest requestWithURL:url];  

[req appendPostData:[str dataUsingEncoding:NSUTF8StringEncoding]];
[req setDelegate:self];
[req setCompletionBlock:^{
    [self parseResult:req];
}];
[req setFailedBlock:^{
    [self requestWentWrong:req];
}];
[req setTag:tag];
[req startAsynchronous];

Is there any way to cancel this request in a button action?

1

There are 1 answers

1
Paresh Navadiya On BEST ANSWER

Add this code in Your button action Event as req is class memeber variable:

-(IBAction)YourbuttonactionEvent
{ 
  if(![req isCancelled]) 
  {
    // Cancels an asynchronous request
    [req cancel];
    // Cancels an asynchronous request, clearing all delegates and blocks first
    [req clearDelegatesAndCancel];
}