Skip to content

Commit 1ab2eed

Browse files
committed
Adding #ifdef macros to conditionally compile reachability features only when the SystemConfiguration is available
1 parent 52559cc commit 1ab2eed

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

AFNetworking/AFHTTPClient.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
164164
/**
165165
Sets a callback to be executed when the network availability of the `baseURL` host changes.
166166
167-
@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`.
167+
@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`.
168+
169+
@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).
168170
*/
171+
#ifdef _SYSTEMCONFIGURATION_H
169172
- (void)setReachabilityStatusChangeBlock:(void (^)(BOOL isNetworkReachable))block;
173+
#endif
170174

171175
///-------------------------------
172176
/// @name Managing HTTP Operations

AFNetworking/AFHTTPClient.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
#import "AFJSONUtilities.h"
2828

2929
#import <Availability.h>
30-
#import <SystemConfiguration/SystemConfiguration.h>
3130

3231
#if __IPHONE_OS_VERSION_MIN_REQUIRED
3332
#import <UIKit/UIKit.h>
3433
#endif
3534

35+
#ifdef _SYSTEMCONFIGURATION_H
36+
#import <SystemConfiguration/SystemConfiguration.h>
37+
#endif
38+
3639
static NSString * const kAFMultipartFormLineDelimiter = @"\r\n"; // CRLF
3740
static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
3841

@@ -50,6 +53,12 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding;
5053

5154
#pragma mark -
5255

56+
#ifdef _SYSTEMCONFIGURATION_H
57+
typedef SCNetworkReachabilityRef AFNetworkReachabilityRef;
58+
#else
59+
typedef id AFNetworkReachabilityRef;
60+
#endif
61+
5362
typedef void (^AFNetworkReachabilityStatusBlock)(BOOL isNetworkReachable);
5463

5564
static NSUInteger const kAFHTTPClientDefaultMaxConcurrentOperationCount = 4;
@@ -127,7 +136,7 @@ @interface AFHTTPClient ()
127136
@property (readwrite, nonatomic, retain) NSMutableArray *registeredHTTPOperationClassNames;
128137
@property (readwrite, nonatomic, retain) NSMutableDictionary *defaultHeaders;
129138
@property (readwrite, nonatomic, retain) NSOperationQueue *operationQueue;
130-
@property (readwrite, nonatomic, assign) SCNetworkReachabilityRef networkReachability;
139+
@property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability;
131140
@property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
132141
@end
133142

@@ -195,6 +204,7 @@ - (void)dealloc {
195204

196205
#pragma mark -
197206

207+
#ifdef _SYSTEMCONFIGURATION_H
198208
static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
199209
if (info) {
200210
AFNetworkReachabilityStatusBlock block = (AFNetworkReachabilityStatusBlock)info;
@@ -215,6 +225,7 @@ - (void)setReachabilityStatusChangeBlock:(void (^)(BOOL isNetworkReachable))bloc
215225
SCNetworkReachabilitySetCallback(self.networkReachability, AFReachabilityCallback, &context);
216226
SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes);
217227
}
228+
#endif
218229

219230
#pragma mark -
220231

iOS Example/Prefix.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#ifdef __OBJC__
88
#import <UIKit/UIKit.h>
99
#import <Foundation/Foundation.h>
10+
#import <SystemConfiguration/SystemConfiguration.h>
1011
#endif

0 commit comments

Comments
 (0)