From d33c5dfeee11dd7791b5ce7aa943084befd52ad6 Mon Sep 17 00:00:00 2001 From: Woody Peterson Date: Tue, 31 Dec 2013 17:55:07 -0800 Subject: [PATCH] Allow subclasses to manipulate reachabilityFlags Previously, many methods made a direct call to SCNetworkReachabilityGetFlags(reachabilityRef, &flags) to get the flags. Since we already have a method that does this, we can "program to an interface" and have all flag queries go through `-reachabilityFlags` to gain readability (IMO) and more importantly the ability of subclasses overriding `-reachabilityFlags` for testing purposes. --- Reachability.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Reachability.m b/Reachability.m index 99aa9f5..42f7799 100644 --- a/Reachability.m +++ b/Reachability.m @@ -335,9 +335,9 @@ -(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags -(BOOL)isReachable { - SCNetworkReachabilityFlags flags; + SCNetworkReachabilityFlags flags = self.reachabilityFlags; - if(!SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + if(!flags) return NO; return [self isReachableWithFlags:flags]; @@ -347,9 +347,9 @@ -(BOOL)isReachableViaWWAN { #if TARGET_OS_IPHONE - SCNetworkReachabilityFlags flags = 0; + SCNetworkReachabilityFlags flags = self.reachabilityFlags; - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + if(flags) { // Check we're REACHABLE if(flags & kSCNetworkReachabilityFlagsReachable) @@ -368,9 +368,9 @@ -(BOOL)isReachableViaWWAN -(BOOL)isReachableViaWiFi { - SCNetworkReachabilityFlags flags = 0; + SCNetworkReachabilityFlags flags = self.reachabilityFlags; - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + if(flags) { // Check we're reachable if((flags & kSCNetworkReachabilityFlagsReachable)) @@ -399,9 +399,9 @@ -(BOOL)isConnectionRequired -(BOOL)connectionRequired { - SCNetworkReachabilityFlags flags; + SCNetworkReachabilityFlags flags = self.reachabilityFlags; - if(SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + if(flags) { return (flags & kSCNetworkReachabilityFlagsConnectionRequired); } @@ -412,9 +412,9 @@ -(BOOL)connectionRequired // Dynamic, on demand connection? -(BOOL)isConnectionOnDemand { - SCNetworkReachabilityFlags flags; + SCNetworkReachabilityFlags flags = self.reachabilityFlags; - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + if (flags) { return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && (flags & (kSCNetworkReachabilityFlagsConnectionOnTraffic | kSCNetworkReachabilityFlagsConnectionOnDemand))); @@ -426,9 +426,9 @@ -(BOOL)isConnectionOnDemand // Is user intervention required? -(BOOL)isInterventionRequired { - SCNetworkReachabilityFlags flags; + SCNetworkReachabilityFlags flags = self.reachabilityFlags; - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) + if (flags) { return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && (flags & kSCNetworkReachabilityFlagsInterventionRequired));