From 68e13764afdf7adfba29e891095542002d8cfe2f Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Wed, 29 Feb 2012 11:43:47 -0600 Subject: [PATCH] Added in cancel changes based on @zdzisiekpu's recommendation Changed connection to be retained, and set the connection to be nil in the cancel, success, and error case. --- AFNetworking/AFURLConnectionOperation.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 076d846..2ad446d 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -85,7 +85,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat @interface AFURLConnectionOperation () @property (readwrite, nonatomic, assign) AFOperationState state; @property (readwrite, nonatomic, retain) NSRecursiveLock *lock; -@property (readwrite, nonatomic, assign) NSURLConnection *connection; +@property (readwrite, nonatomic, retain) NSURLConnection *connection; @property (readwrite, nonatomic, retain) NSURLRequest *request; @property (readwrite, nonatomic, retain) NSURLResponse *response; @property (readwrite, nonatomic, retain) NSError *error; @@ -351,6 +351,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat - (void)cancelConnection { if (self.connection) { [self.connection cancel]; + self.connection = nil; // 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]; @@ -466,6 +467,8 @@ didReceiveResponse:(NSURLResponse *)response } [self finish]; + + self.connection = nil; } - (void)connection:(NSURLConnection *)__unused connection @@ -480,6 +483,8 @@ didReceiveResponse:(NSURLResponse *)response } [self finish]; + + self.connection = nil; } - (NSCachedURLResponse *)connection:(NSURLConnection *)__unused connection