From 1ab2eed8c8fcee1cecaaf9339d6a668db589e988 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 19 Jan 2012 17:26:12 -0800 Subject: [PATCH] Adding #ifdef macros to conditionally compile reachability features only when the SystemConfiguration is available --- AFNetworking/AFHTTPClient.h | 6 +++++- AFNetworking/AFHTTPClient.m | 15 +++++++++++++-- iOS Example/Prefix.pch | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 5cc6913..9efe467 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -164,9 +164,13 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete /** Sets a callback to be executed when the network availability of the `baseURL` host changes. - @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument, which is `YES` if the host is available, otherwise `NO`. + @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument, which is `YES` if the host is available, otherwise `NO`. + + @warning This method requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). */ +#ifdef _SYSTEMCONFIGURATION_H - (void)setReachabilityStatusChangeBlock:(void (^)(BOOL isNetworkReachable))block; +#endif ///------------------------------- /// @name Managing HTTP Operations diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index b101882..8b36289 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -27,12 +27,15 @@ #import "AFJSONUtilities.h" #import -#import #if __IPHONE_OS_VERSION_MIN_REQUIRED #import #endif +#ifdef _SYSTEMCONFIGURATION_H +#import +#endif + static NSString * const kAFMultipartFormLineDelimiter = @"\r\n"; // CRLF static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY"; @@ -50,6 +53,12 @@ static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY" #pragma mark - +#ifdef _SYSTEMCONFIGURATION_H +typedef SCNetworkReachabilityRef AFNetworkReachabilityRef; +#else +typedef id AFNetworkReachabilityRef; +#endif + typedef void (^AFNetworkReachabilityStatusBlock)(BOOL isNetworkReachable); static NSUInteger const kAFHTTPClientDefaultMaxConcurrentOperationCount = 4; @@ -127,7 +136,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { @property (readwrite, nonatomic, retain) NSMutableArray *registeredHTTPOperationClassNames; @property (readwrite, nonatomic, retain) NSMutableDictionary *defaultHeaders; @property (readwrite, nonatomic, retain) NSOperationQueue *operationQueue; -@property (readwrite, nonatomic, assign) SCNetworkReachabilityRef networkReachability; +@property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability; @property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock; @end @@ -195,6 +204,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { #pragma mark - +#ifdef _SYSTEMCONFIGURATION_H static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) { if (info) { AFNetworkReachabilityStatusBlock block = (AFNetworkReachabilityStatusBlock)info; @@ -215,6 +225,7 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN SCNetworkReachabilitySetCallback(self.networkReachability, AFReachabilityCallback, &context); SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes); } +#endif #pragma mark - diff --git a/iOS Example/Prefix.pch b/iOS Example/Prefix.pch index 47d76c1..0cb5c10 100644 --- a/iOS Example/Prefix.pch +++ b/iOS Example/Prefix.pch @@ -7,4 +7,5 @@ #ifdef __OBJC__ #import #import + #import #endif