Iphone stops ASIFormDataRequest

I have a problem with my viewController when I have a pending ASIFormDataRequest (running as an asynchronous task) that is still running and the user clicks the back button (to display the view).

Can this asynchronous task be stopped?

I read that this is a method called clearDelegatesAndCancel, but I don’t know, this is what I am looking for.

thank

+3
source share
2 answers

The thing is, to invoke clearDelegatesAndCancel, you must have an ASIFromDataRequest object handle that runs asynchronously. This means that you must configure it as a property, for example ...

@interface MyViewController : UIViewController <ASIHTTPRequestDelegate>
{
    ASIFormDataRequest *theRequest
    ...
}

@property (nonatomic, retain) ASIFormDataRequest *theRequest;

Then in your .m do not declare a new request object, just assign your formdatarequest to the iVar class:

@synthesize theRequest;

-(void)viewDidLoad  //or whatever
{
    self.theRequest = [ASIFormDataRequest requestWithUrl:myUrl];
    // then configure and fire the request, being sure to set .delegate to self
}

-(void)viewWillDisappear:(BOOL)animated //or whatever
{ 
   [self.theRequest clearDelegatesAndCancel];
}

 -(void)dealloc
{
    [theRequest release];  //don't not do this.
}

, , , .

, . viewcontroller (, UINavController) , , .

+6

ASI (http://allseeing-i.com/ASIHTTPRequest/How-to-use)

    To cancel an asynchronous request (either a request that was started with
    [request startAsynchronous] or a request running in a queue you created),
    call [request cancel]. Note that you cannot cancel a synchronous request.

    Note that when you cancel a request, the request will treat that as an error,
    and will call your delegate and/or queue’s failure delegate method. If you do
    not want this behaviour, set your delegate to nil before calling cancel, or
    use the clearDelegatesAndCancel method instead.
+3

Source: https://habr.com/ru/post/1787725/


All Articles