From 7b685fe35efd574fdd5b779c12ff2577f5a27814 Mon Sep 17 00:00:00 2001 From: Evadne Wu Date: Thu, 27 Dec 2012 12:19:13 -0500 Subject: [PATCH] dispatches network request start / end notifications asynchronously Signed-off-by: Mattt Thompson --- AFNetworking/AFURLConnectionOperation.m | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 675476b..e6cd729 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -331,17 +331,19 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat _state = state; [self didChangeValueForKey:oldStateKey]; [self didChangeValueForKey:newStateKey]; - - switch (state) { - case AFOperationExecutingState: - [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidStartNotification object:self]; - break; - case AFOperationFinishedState: - [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self]; - break; - default: - break; - } + + dispatch_async(dispatch_get_main_queue(), ^{ + switch (state) { + case AFOperationExecutingState: + [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidStartNotification object:self]; + break; + case AFOperationFinishedState: + [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self]; + break; + default: + break; + } + }); } [self.lock unlock]; }