Calling instance method cancel on an NSURLConnection most often don't cancel the connection at all.
I'm performing an asynchronous NSURLConnection in an NSOperation. If the operation is cancelled, the connection is stopped by calling cancel on NSURLConnection and then setting the connection to nil.
Is there a way to cancel the connection immediatly? Most often it continues running in the background until the request is finished even though both the connection is canceled and set to nil. The NSOperation subclass is dealloced after the connection is canceled, where the connection is released. Even after that, the asynchronous connection continues running!
Is there another way to cancel it? Or can the thread its running on be canceled?
Here is a code snippet from my NSOperation subclass main method:
// Create and start asynchronous connection
self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
[request release];
while(!isFinished) {
if(self.isCancelled) {
[self.connection cancel];
self.connection = nil;
[self uploadCanceledDelegate];
return;
}
// Special sleep because callbacks are executed on same thread as this loop
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
NOTE: This behaviour only occur when WiFi is enabled. With 3G/Edge/GPRS it works fine