4 Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
10 Significant additions made by Andrew W. Donoho, August 11, 2009.
11 This is a derived work of Apple's Reachability v2.0 class.
13 The below license is the new BSD license with the OSI recommended personalizations.
14 <http://www.opensource.org/licenses/bsd-license.php>
16 Extensions Copyright (C) 2009 Donoho Design Group, LLC. All Rights Reserved.
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are
22 * Redistributions of source code must retain the above copyright notice,
23 this list of conditions and the following disclaimer.
25 * Redistributions in binary form must reproduce the above copyright
26 notice, this list of conditions and the following disclaimer in the
27 documentation and/or other materials provided with the distribution.
29 * Neither the name of Andrew W. Donoho nor Donoho Design Group, L.L.C.
30 may be used to endorse or promote products derived from this software
31 without specific prior written permission.
33 THIS SOFTWARE IS PROVIDED BY DONOHO DESIGN GROUP, L.L.C. "AS IS" AND ANY
34 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
37 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 Apple's Original License on Reachability v2.0
52 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
53 ("Apple") in consideration of your agreement to the following terms, and your
54 use, installation, modification or redistribution of this Apple software
55 constitutes acceptance of these terms. If you do not agree with these terms,
56 please do not use, install, modify or redistribute this Apple software.
58 In consideration of your agreement to abide by the following terms, and subject
59 to these terms, Apple grants you a personal, non-exclusive license, under
60 Apple's copyrights in this original Apple software (the "Apple Software"), to
61 use, reproduce, modify and redistribute the Apple Software, with or without
62 modifications, in source and/or binary forms; provided that if you redistribute
63 the Apple Software in its entirety and without modifications, you must retain
64 this notice and the following text and disclaimers in all such redistributions
65 of the Apple Software.
67 Neither the name, trademarks, service marks or logos of Apple Inc. may be used
68 to endorse or promote products derived from the Apple Software without specific
69 prior written permission from Apple. Except as expressly stated in this notice,
70 no other rights or licenses, express or implied, are granted by Apple herein,
71 including but not limited to any patent rights that may be infringed by your
72 derivative works or by other works in which the Apple Software may be
75 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
76 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
77 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
78 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
79 COMBINATION WITH YOUR PRODUCTS.
81 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
82 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
83 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
85 DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
86 CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
87 APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89 Copyright (C) 2009 Apple Inc. All Rights Reserved.
94 Each reachability object now has a copy of the key used to store it in a dictionary.
95 This allows each observer to quickly determine if the event is important to them.
98 #import <sys/socket.h>
99 #import <netinet/in.h>
100 #import <netinet6/in6.h>
101 #import <arpa/inet.h>
105 #import <CoreFoundation/CoreFoundation.h>
107 #import "Reachability.h"
109 NSString *const kInternetConnection = @"InternetConnection";
110 NSString *const kLocalWiFiConnection = @"LocalWiFiConnection";
111 NSString *const kReachabilityChangedNotification = @"NetworkReachabilityChangedNotification";
113 #define CLASS_DEBUG 1 // Turn on logReachabilityFlags. Must also have a project wide defined DEBUG.
115 #if (defined DEBUG && defined CLASS_DEBUG)
116 #define logReachabilityFlags(flags) (logReachabilityFlags_(__PRETTY_FUNCTION__, __LINE__, flags))
118 static NSString *reachabilityFlags_(SCNetworkReachabilityFlags flags) {
120 #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 30000) // Apple advises you to use the magic number instead of a symbol.
121 return [NSString stringWithFormat:@"Reachability Flags: %c%c %c%c%c%c%c%c%c",
122 (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-',
123 (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-',
125 (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-',
126 (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-',
127 (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-',
128 (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-',
129 (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-',
130 (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-',
131 (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-'];
133 // Compile out the v3.0 features for v2.2.1 deployment.
134 return [NSString stringWithFormat:@"Reachability Flags: %c%c %c%c%c%c%c%c",
135 (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-',
136 (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-',
138 (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-',
139 (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-',
140 (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-',
141 // v3 kSCNetworkReachabilityFlagsConnectionOnTraffic == v2 kSCNetworkReachabilityFlagsConnectionAutomatic
142 (flags & kSCNetworkReachabilityFlagsConnectionAutomatic) ? 'C' : '-',
143 // (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', // No v2 equivalent.
144 (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-',
145 (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-'];
148 } // reachabilityFlags_()
150 static void logReachabilityFlags_(const char *name, int line, SCNetworkReachabilityFlags flags) {
152 NSLog(@"%s (%d) \n\t%@", name, line, reachabilityFlags_(flags));
154 } // logReachabilityFlags_()
156 #define logNetworkStatus(status) (logNetworkStatus_(__PRETTY_FUNCTION__, __LINE__, status))
158 static void logNetworkStatus_(const char *name, int line, NetworkStatus status) {
160 NSString *statusString = nil;
164 statusString = [NSString stringWithString: @"Not Reachable"];
166 case kReachableViaWWAN:
167 statusString = [NSString stringWithString: @"Reachable via WWAN"];
169 case kReachableViaWiFi:
170 statusString = [NSString stringWithString: @"Reachable via WiFi"];
174 NSLog(@"%s (%d) \n\tNetwork Status: %@", name, line, statusString);
176 } // logNetworkStatus_()
179 #define logReachabilityFlags(flags)
180 #define logNetworkStatus(status)
183 @interface Reachability (private)
185 - (NetworkStatus) networkStatusForFlags: (SCNetworkReachabilityFlags) flags;
189 @implementation Reachability
191 @synthesize key = key_;
193 // Preclude direct access to ivars.
194 + (BOOL) accessInstanceVariablesDirectly {
198 } // accessInstanceVariablesDirectly
204 if(reachabilityRef) {
206 CFRelease(reachabilityRef); reachabilityRef = NULL;
217 - (Reachability *) initWithReachabilityRef: (SCNetworkReachabilityRef) ref
222 reachabilityRef = ref;
227 } // initWithReachabilityRef:
230 #if (defined DEBUG && defined CLASS_DEBUG)
231 - (NSString *) description {
233 NSAssert(reachabilityRef, @"-description called with NULL reachabilityRef");
235 SCNetworkReachabilityFlags flags = 0;
237 SCNetworkReachabilityGetFlags(reachabilityRef, &flags);
239 return [NSString stringWithFormat: @"%@\n\t%@", self.key, reachabilityFlags_(flags)];
246 #pragma mark Notification Management Methods
249 //Start listening for reachability notifications on the current run loop
250 static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) {
252 #pragma unused (target, flags)
253 NSCAssert(info, @"info was NULL in ReachabilityCallback");
254 NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was the wrong class in ReachabilityCallback");
256 //We're on the main RunLoop, so an NSAutoreleasePool is not necessary, but is added defensively
257 // in case someone uses the Reachablity object in a different thread.
258 NSAutoreleasePool* pool = [NSAutoreleasePool new];
260 // Post a notification to notify the client that the network reachability changed.
261 [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification
262 object: (Reachability *) info];
266 } // ReachabilityCallback()
269 - (BOOL) startNotifier {
271 SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL};
273 if(SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context)) {
275 if(SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
288 - (void) stopNotifier {
290 if(reachabilityRef) {
292 SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
299 - (BOOL) isEqual: (Reachability *) r {
301 return [r.key isEqualToString: self.key];
307 #pragma mark Reachability Allocation Methods
310 + (Reachability *) reachabilityWithHostName: (NSString *) hostName {
312 SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]);
316 Reachability *r = [[[self alloc] initWithReachabilityRef: ref] autorelease];
326 } // reachabilityWithHostName
329 + (NSString *) makeAddressKey: (in_addr_t) addr {
330 // addr is assumed to be in network byte order.
332 static const int highShift = 24;
333 static const int highMidShift = 16;
334 static const int lowMidShift = 8;
335 static const in_addr_t mask = 0x000000ff;
339 return [NSString stringWithFormat: @"%d.%d.%d.%d",
340 (addr >> highShift) & mask,
341 (addr >> highMidShift) & mask,
342 (addr >> lowMidShift) & mask,
348 + (Reachability *) reachabilityWithAddress: (const struct sockaddr_in *) hostAddress {
350 SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
354 Reachability *r = [[[self alloc] initWithReachabilityRef: ref] autorelease];
356 r.key = [self makeAddressKey: hostAddress->sin_addr.s_addr];
364 } // reachabilityWithAddress
367 + (Reachability *) reachabilityForInternetConnection {
369 struct sockaddr_in zeroAddress;
370 bzero(&zeroAddress, sizeof(zeroAddress));
371 zeroAddress.sin_len = sizeof(zeroAddress);
372 zeroAddress.sin_family = AF_INET;
374 Reachability *r = [self reachabilityWithAddress: &zeroAddress];
376 r.key = kInternetConnection;
380 } // reachabilityForInternetConnection
383 + (Reachability *) reachabilityForLocalWiFi {
385 struct sockaddr_in localWifiAddress;
386 bzero(&localWifiAddress, sizeof(localWifiAddress));
387 localWifiAddress.sin_len = sizeof(localWifiAddress);
388 localWifiAddress.sin_family = AF_INET;
389 // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
390 localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
392 Reachability *r = [self reachabilityWithAddress: &localWifiAddress];
394 r.key = kLocalWiFiConnection;
398 } // reachabilityForLocalWiFi
402 #pragma mark Network Flag Handling Methods
405 #if USE_DDG_EXTENSIONS
407 // iPhone condition codes as reported by a 3GS running iPhone OS v3.0.
408 // Airplane Mode turned on: Reachability Flag Status: -- -------
409 // WWAN Active: Reachability Flag Status: WR -t-----
410 // WWAN Connection required: Reachability Flag Status: WR ct-----
411 // WiFi turned on: Reachability Flag Status: -R ------- Reachable.
412 // Local WiFi turned on: Reachability Flag Status: -R xxxxxxd Reachable.
413 // WiFi turned on: Reachability Flag Status: -R ct----- Connection down. (Non-intuitive, empirically determined answer.)
414 const SCNetworkReachabilityFlags kConnectionDown = kSCNetworkReachabilityFlagsConnectionRequired |
415 kSCNetworkReachabilityFlagsTransientConnection;
416 // WiFi turned on: Reachability Flag Status: -R ct-i--- Reachable but it will require user intervention (e.g. enter a WiFi password).
417 // WiFi turned on: Reachability Flag Status: -R -t----- Reachable via VPN.
419 // In the below method, an 'x' in the flag status means I don't care about its value.
421 // This method differs from Apple's by testing explicitly for empirically observed values.
422 // This gives me more confidence in it's correct behavior. Apple's code covers more cases
423 // than mine. My code covers the cases that occur.
425 - (NetworkStatus) networkStatusForFlags: (SCNetworkReachabilityFlags) flags {
427 if (flags & kSCNetworkReachabilityFlagsReachable) {
429 // Local WiFi -- Test derived from Apple's code: -localWiFiStatusForFlags:.
430 if (self.key == kLocalWiFiConnection) {
432 // Reachability Flag Status: xR xxxxxxd Reachable.
433 return (flags & kSCNetworkReachabilityFlagsIsDirect) ? kReachableViaWiFi : kNotReachable;
437 // Observed WWAN Values:
438 // WWAN Active: Reachability Flag Status: WR -t-----
439 // WWAN Connection required: Reachability Flag Status: WR ct-----
441 // Test Value: Reachability Flag Status: WR xxxxxxx
442 if (flags & kSCNetworkReachabilityFlagsIsWWAN) { return kReachableViaWWAN; }
445 flags &= ~kSCNetworkReachabilityFlagsReachable;
446 flags &= ~kSCNetworkReachabilityFlagsIsDirect;
447 flags &= ~kSCNetworkReachabilityFlagsIsLocalAddress; // kInternetConnection is local.
449 // Reachability Flag Status: -R ct---xx Connection down.
450 if (flags == kConnectionDown) { return kNotReachable; }
452 // Reachability Flag Status: -R -t---xx Reachable. WiFi + VPN(is up) (Thank you Ling Wang)
453 if (flags & kSCNetworkReachabilityFlagsTransientConnection) { return kReachableViaWiFi; }
455 // Reachability Flag Status: -R -----xx Reachable.
456 if (flags == 0) { return kReachableViaWiFi; }
458 // Apple's code tests for dynamic connection types here. I don't.
459 // If a connection is required, regardless of whether it is on demand or not, it is a WiFi connection.
460 // If you care whether a connection needs to be brought up, use -isConnectionRequired.
461 // If you care about whether user intervention is necessary, use -isInterventionRequired.
462 // If you care about dynamically establishing the connection, use -isConnectionIsOnDemand.
464 // Reachability Flag Status: -R cxxxxxx Reachable.
465 if (flags & kSCNetworkReachabilityFlagsConnectionRequired) { return kReachableViaWiFi; }
467 // Required by the compiler. Should never get here. Default to not connected.
468 #if (defined DEBUG && defined CLASS_DEBUG)
469 NSAssert1(NO, @"Uncaught reachability test. Flags: %@", reachabilityFlags_(flags));
471 return kNotReachable;
475 // Reachability Flag Status: x- xxxxxxx
476 return kNotReachable;
478 } // networkStatusForFlags:
481 - (NetworkStatus) currentReachabilityStatus {
483 NSAssert(reachabilityRef, @"currentReachabilityStatus called with NULL reachabilityRef");
485 SCNetworkReachabilityFlags flags = 0;
486 NetworkStatus status = kNotReachable;
488 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
490 // logReachabilityFlags(flags);
492 status = [self networkStatusForFlags: flags];
498 return kNotReachable;
500 } // currentReachabilityStatus
503 - (BOOL) isReachable {
505 NSAssert(reachabilityRef, @"isReachable called with NULL reachabilityRef");
507 SCNetworkReachabilityFlags flags = 0;
508 NetworkStatus status = kNotReachable;
510 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
512 // logReachabilityFlags(flags);
514 status = [self networkStatusForFlags: flags];
516 // logNetworkStatus(status);
518 return (kNotReachable != status);
527 - (BOOL) isConnectionRequired {
529 NSAssert(reachabilityRef, @"isConnectionRequired called with NULL reachabilityRef");
531 SCNetworkReachabilityFlags flags;
533 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
535 logReachabilityFlags(flags);
537 return (flags & kSCNetworkReachabilityFlagsConnectionRequired);
543 } // isConnectionRequired
546 - (BOOL) connectionRequired {
548 return [self isConnectionRequired];
550 } // connectionRequired
554 #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 30000)
555 static const SCNetworkReachabilityFlags kOnDemandConnection = kSCNetworkReachabilityFlagsConnectionOnTraffic |
556 kSCNetworkReachabilityFlagsConnectionOnDemand;
558 static const SCNetworkReachabilityFlags kOnDemandConnection = kSCNetworkReachabilityFlagsConnectionAutomatic;
561 - (BOOL) isConnectionOnDemand {
563 NSAssert(reachabilityRef, @"isConnectionIsOnDemand called with NULL reachabilityRef");
565 SCNetworkReachabilityFlags flags;
567 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
569 logReachabilityFlags(flags);
571 return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) &&
572 (flags & kOnDemandConnection));
578 } // isConnectionOnDemand
581 - (BOOL) isInterventionRequired {
583 NSAssert(reachabilityRef, @"isInterventionRequired called with NULL reachabilityRef");
585 SCNetworkReachabilityFlags flags;
587 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
589 logReachabilityFlags(flags);
591 return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) &&
592 (flags & kSCNetworkReachabilityFlagsInterventionRequired));
598 } // isInterventionRequired
601 - (BOOL) isReachableViaWWAN {
603 NSAssert(reachabilityRef, @"isReachableViaWWAN called with NULL reachabilityRef");
605 SCNetworkReachabilityFlags flags = 0;
606 NetworkStatus status = kNotReachable;
608 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
610 logReachabilityFlags(flags);
612 status = [self networkStatusForFlags: flags];
614 return (kReachableViaWWAN == status);
620 } // isReachableViaWWAN
623 - (BOOL) isReachableViaWiFi {
625 NSAssert(reachabilityRef, @"isReachableViaWiFi called with NULL reachabilityRef");
627 SCNetworkReachabilityFlags flags = 0;
628 NetworkStatus status = kNotReachable;
630 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
632 logReachabilityFlags(flags);
634 status = [self networkStatusForFlags: flags];
636 return (kReachableViaWiFi == status);
642 } // isReachableViaWiFi
645 - (SCNetworkReachabilityFlags) reachabilityFlags {
647 NSAssert(reachabilityRef, @"reachabilityFlags called with NULL reachabilityRef");
649 SCNetworkReachabilityFlags flags = 0;
651 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
653 logReachabilityFlags(flags);
661 } // reachabilityFlags
665 #pragma mark Apple's Network Flag Handling Methods
668 #if !USE_DDG_EXTENSIONS
671 * Apple's Network Status testing code.
672 * The only changes that have been made are to use the new logReachabilityFlags macro and
673 * test for local WiFi via the key instead of Apple's boolean. Also, Apple's code was for v3.0 only
674 * iPhone OS. v2.2.1 and earlier conditional compiling is turned on. Hence, to mirror Apple's behavior,
675 * set your Base SDK to v3.0 or higher.
679 - (NetworkStatus) localWiFiStatusForFlags: (SCNetworkReachabilityFlags) flags
681 logReachabilityFlags(flags);
683 BOOL retVal = NotReachable;
684 if((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect))
686 retVal = ReachableViaWiFi;
692 - (NetworkStatus) networkStatusForFlags: (SCNetworkReachabilityFlags) flags
694 logReachabilityFlags(flags);
695 if (!(flags & kSCNetworkReachabilityFlagsReachable))
697 // if target host is not reachable
701 BOOL retVal = NotReachable;
703 if (!(flags & kSCNetworkReachabilityFlagsConnectionRequired))
705 // if target host is reachable and no connection is required
706 // then we'll assume (for now) that your on Wi-Fi
707 retVal = ReachableViaWiFi;
710 #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 30000) // Apple advises you to use the magic number instead of a symbol.
711 if ((flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ||
712 (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic))
714 if (flags & kSCNetworkReachabilityFlagsConnectionAutomatic)
717 // ... and the connection is on-demand (or on-traffic) if the
718 // calling application is using the CFSocketStream or higher APIs
720 if (!(flags & kSCNetworkReachabilityFlagsInterventionRequired))
722 // ... and no [user] intervention is needed
723 retVal = ReachableViaWiFi;
727 if (flags & kSCNetworkReachabilityFlagsIsWWAN)
729 // ... but WWAN connections are OK if the calling application
730 // is using the CFNetwork (CFSocketStream?) APIs.
731 retVal = ReachableViaWWAN;
737 - (NetworkStatus) currentReachabilityStatus
739 NSAssert(reachabilityRef, @"currentReachabilityStatus called with NULL reachabilityRef");
741 NetworkStatus retVal = NotReachable;
742 SCNetworkReachabilityFlags flags;
743 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags))
745 if(self.key == kLocalWiFiConnection)
747 retVal = [self localWiFiStatusForFlags: flags];
751 retVal = [self networkStatusForFlags: flags];
758 - (BOOL) isReachable {
760 NSAssert(reachabilityRef, @"isReachable called with NULL reachabilityRef");
762 SCNetworkReachabilityFlags flags = 0;
763 NetworkStatus status = kNotReachable;
765 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
767 logReachabilityFlags(flags);
769 if(self.key == kLocalWiFiConnection) {
771 status = [self localWiFiStatusForFlags: flags];
775 status = [self networkStatusForFlags: flags];
779 return (kNotReachable != status);
788 - (BOOL) isConnectionRequired {
790 return [self connectionRequired];
792 } // isConnectionRequired
795 - (BOOL) connectionRequired {
797 NSAssert(reachabilityRef, @"connectionRequired called with NULL reachabilityRef");
799 SCNetworkReachabilityFlags flags;
801 if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
803 logReachabilityFlags(flags);
805 return (flags & kSCNetworkReachabilityFlagsConnectionRequired);
811 } // connectionRequired