Adding #ifdef macros to conditionally compile reachability features only when the SystemConfiguration is available

This commit is contained in:
Mattt Thompson 2012-01-19 17:26:12 -08:00
parent 52559ccec3
commit 1ab2eed8c8
3 changed files with 19 additions and 3 deletions

View file

@ -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 <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (Prefix.pch).
*/
#ifdef _SYSTEMCONFIGURATION_H
- (void)setReachabilityStatusChangeBlock:(void (^)(BOOL isNetworkReachable))block;
#endif
///-------------------------------
/// @name Managing HTTP Operations

View file

@ -27,12 +27,15 @@
#import "AFJSONUtilities.h"
#import <Availability.h>
#import <SystemConfiguration/SystemConfiguration.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED
#import <UIKit/UIKit.h>
#endif
#ifdef _SYSTEMCONFIGURATION_H
#import <SystemConfiguration/SystemConfiguration.h>
#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 -

View file

@ -7,4 +7,5 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#endif