Minor formatting changes
Adding line comment about why cancelConnection is being called as it is Minor edit to comment about manually sending delegate message on cancel
This commit is contained in:
parent
f0ce3a86e3
commit
e0831197d3
1 changed files with 19 additions and 16 deletions
|
|
@ -334,29 +334,32 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
self.state = AFHTTPOperationFinishedState;
|
self.state = AFHTTPOperationFinishedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)cancelConnection {
|
- (void)cancel {
|
||||||
|
[self.lock lock];
|
||||||
|
if (![self isFinished] && ![self isCancelled]) {
|
||||||
|
[super cancel];
|
||||||
|
|
||||||
|
// Cancel the connection on the thread it runs on to prevent race conditions
|
||||||
|
[self performSelector:@selector(cancelConnection) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self.lock unlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cancelConnection {
|
||||||
[self willChangeValueForKey:@"isCancelled"];
|
[self willChangeValueForKey:@"isCancelled"];
|
||||||
_cancelled = YES;
|
_cancelled = YES;
|
||||||
|
|
||||||
if (self.connection) {
|
if (self.connection) {
|
||||||
[self.connection cancel];
|
[self.connection cancel];
|
||||||
//We must send this delegate protcol message ourselves since the above [self.connection cancel] causes the connection to never send another message to its delegate.
|
|
||||||
|
// Manually send this delegate message since `[self.connection cancel]` causes the connection to never send another message to its delegate
|
||||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||||
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self didChangeValueForKey:@"isCancelled"];
|
[self didChangeValueForKey:@"isCancelled"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancel {
|
|
||||||
[self.lock lock];
|
|
||||||
if (![self isFinished] && ![self isCancelled]) {
|
|
||||||
[super cancel];
|
|
||||||
[self performSelector:@selector(cancelConnection) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
|
||||||
}
|
|
||||||
[self.lock unlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - NSURLConnectionDelegate
|
#pragma mark - NSURLConnectionDelegate
|
||||||
|
|
||||||
- (BOOL)connection:(NSURLConnection *)connection
|
- (BOOL)connection:(NSURLConnection *)connection
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue