Skip to content
Browse files

[Issue #512] Automatically stop / start network reachability monitori…

…ng when app is made inactive / activated
  • Loading branch information...
1 parent a4508ac commit 82fba385bfe0c51cacafc4d5eb5bcae385b0b1c0 @mattt mattt committed Sep 14, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 AFNetworking/AFHTTPClient.m
View
9 AFNetworking/AFHTTPClient.m
@@ -266,6 +266,11 @@ - (id)initWithBaseURL:(NSURL *)url {
#ifdef _SYSTEMCONFIGURATION_H
self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
[self startMonitoringNetworkReachability];
+
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopMonitoringNetworkReachability) name:UIApplicationWillResignActiveNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startMonitoringNetworkReachability) name:UIApplicationDidBecomeActiveNotification object:nil];
+ #endif
#endif
self.operationQueue = [[[NSOperationQueue alloc] init] autorelease];
@@ -276,6 +281,7 @@ - (id)initWithBaseURL:(NSURL *)url {
- (void)dealloc {
#ifdef _SYSTEMCONFIGURATION_H
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[self stopMonitoringNetworkReachability];
[_networkReachabilityStatusBlock release];
#endif
@@ -284,7 +290,7 @@ - (void)dealloc {
[_registeredHTTPOperationClassNames release];
[_defaultHeaders release];
[_operationQueue release];
-
+
[super dealloc];
}
@@ -377,6 +383,7 @@ - (void)stopMonitoringNetworkReachability {
if (_networkReachability) {
SCNetworkReachabilityUnscheduleFromRunLoop(_networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes);
CFRelease(_networkReachability);
+ _networkReachability = nil;
}
}

0 comments on commit 82fba38

Please sign in to comment.
Something went wrong with that request. Please try again.