How to end an asynchronous http connection on iphone?

I initiated an asynchronous HTTP call on the server in the view manager, but sometimes it takes a lot of time.

Is it possible to put a button on it, and then interrupt a running http call when the user clicked that button? and if this could be done, I would also like to implement this function when the user leaves the current view, go to its parent view.

+3
source share
2 answers

Assuming you are using NSURLConnection, just save the connection object in ivar or property, and then call cancel when you want to cancel the connection.

:

- (IBAction)tapCancelButton:(id)sender {
    [self.connection cancel];
    self.connection = nil;
}
+2

, NSURLConnection. / , :

NSURLConnection ,

0

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


All Articles