I'm trying to add in the ability to cancel all current asynchronous requests when the user leaves the view or when they initiate a new request. I know where to put the code, but I'm not quite sure how to actually cancel the request. From my research, I know that NSURLConnection
has a cancel
method, but I'm calling my requests using asynchronous blocks. Below is my code - any help is greatly appreciated!
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:[kEndpointEvents stringByAppendingString:arguments]]];
//Send an asynchronous request so it doesn't pause the main thread
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSHTTPURLResponse *responseCode = (NSHTTPURLResponse *)response;
//Do stuff
}];