From a9b9ebee376058546837d5114cdbd9a114483729 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 27 Dec 2012 12:22:46 -0500 Subject: [PATCH] Asynchronously posting all notifications by dispatching to main --- AFNetworking/AFHTTPClient.m | 4 +++- AFNetworking/AFURLConnectionOperation.m | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index dd89721..3c896d9 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -301,7 +301,9 @@ static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused targ block(status); } - [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:status] forKey:AFNetworkingReachabilityNotificationStatusItem]]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:status] forKey:AFNetworkingReachabilityNotificationStatusItem]]; + }); } static const void * AFNetworkReachabilityRetainCallback(const void *info) { diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index e6cd729..0d27490 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -385,7 +385,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat if ([self isExecuting]) { [self.connection performSelector:@selector(cancel) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]]; - [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self]; + }); } self.state = AFOperationPausedState;