Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed symbols and added some code.

  • Loading branch information...
commit 56e68da1a0f1cea615ad4f2575b0c186831e3678 1 parent 89a9fd3
@lakesoft lakesoft authored
Showing with 35 additions and 20 deletions.
  1. +6 −6 FBNetworkReachability.h
  2. +29 −14 FBNetworkReachability.m
View
12 FBNetworkReachability.h
@@ -24,11 +24,11 @@
#import <SystemConfiguration/SystemConfiguration.h>
typedef enum {
- kNetworkReachableUninitialization = 0,
- kNetworkReachableNon,
- kNetworkReachableWiFi,
- kNetworkReachableWWAN
-} NetworkReachabilityConnectionMode;
+ FBNetworkReachableUninitialization = 0,
+ FBNetworkReachableNon,
+ FBNetworkReachableWiFi,
+ FBNetworkReachableWWAN
+} FBNetworkReachabilityConnectionMode;
#define FBNetworkReachabilityDidChangeNotification @"FBNetworkReachabilityDidChangeNotification"
@@ -38,7 +38,7 @@ typedef enum {
}
// API
-@property (assign, readonly) NetworkReachabilityConnectionMode connectionMode;
+@property (assign, readonly) FBNetworkReachabilityConnectionMode connectionMode;
@property (assign, readonly) BOOL reachable;
@property (copy, readonly) NSString* ipaddress;
+ (FBNetworkReachability*)networkReachabilityWithHostname:(NSString *)hostname;
View
43 FBNetworkReachability.m
@@ -30,7 +30,7 @@
@interface FBNetworkReachability()
-@property (assign) NetworkReachabilityConnectionMode connectionMode;
+@property (assign) FBNetworkReachabilityConnectionMode connectionMode;
@property (copy) NSString* ipaddress;
- (BOOL)_startNotifier;
- (void)_stopNotifier;
@@ -39,7 +39,7 @@ - (void)_stopNotifier;
@implementation FBNetworkReachability
-@synthesize connectionMode;
+@synthesize connectionMode = connectionMode_;
@synthesize ipaddress;
//------------------------------------------------------------------------------
@@ -53,7 +53,7 @@ - (id)initWithHostname:(NSString*)hostname
reachability_=
SCNetworkReachabilityCreateWithName(kCFAllocatorDefault,
[hostname UTF8String]);
- self.connectionMode = kNetworkReachableUninitialization;
+ self.connectionMode = FBNetworkReachableUninitialization;
[self _startNotifier];
}
return self;
@@ -123,21 +123,21 @@ - (NSString*)_getIPAddressWiFilEnabled:(BOOL)wifiEnabled
// 0: no connection
// 1: celluar connection
// 2: wifi connection
-- (NetworkReachabilityConnectionMode)_getConnectionModeWithFlags:(SCNetworkReachabilityFlags)flags
+- (FBNetworkReachabilityConnectionMode)_getConnectionModeWithFlags:(SCNetworkReachabilityFlags)flags
{
BOOL isReachable = ((flags & kSCNetworkFlagsReachable) != 0);
BOOL needsConnection = ((flags & kSCNetworkFlagsConnectionRequired) != 0);
if (isReachable && !needsConnection) {
if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
- return kNetworkReachableWWAN;
+ return FBNetworkReachableWWAN;
}
if ([self _getIPAddressWiFilEnabled:YES]) {
- return kNetworkReachableWiFi;
+ return FBNetworkReachableWiFi;
}
}
- return kNetworkReachableNon;
+ return FBNetworkReachableNon;
}
@@ -217,14 +217,29 @@ - (NSString*)IPAddress
//------------------------------------------------------------------------------
- (BOOL)reachable
{
- if (self.connectionMode == kNetworkReachableWiFi ||
- self.connectionMode == kNetworkReachableWWAN) {
+ if (self.connectionMode == FBNetworkReachableWiFi ||
+ self.connectionMode == FBNetworkReachableWWAN) {
return YES;
} else {
return NO;
}
}
-
+- (FBNetworkReachabilityConnectionMode)connectionMode
+{
+ @synchronized (self) {
+ if (connectionMode_ == FBNetworkReachableUninitialization) {
+ [[NSRunLoop currentRunLoop]
+ runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
+ }
+ return connectionMode_;
+ }
+}
+- (void)setConnectionMode:(FBNetworkReachabilityConnectionMode)connectionMode
+{
+ @synchronized (self) {
+ connectionMode_ = connectionMode;
+ }
+}
//------------------------------------------------------------------------------
#pragma mark -
@@ -235,19 +250,19 @@ - (NSString*)description
NSString* desc = nil;
switch (self.connectionMode) {
- case kNetworkReachableUninitialization:
+ case FBNetworkReachableUninitialization:
desc = @"Not initialized";
break;
- case kNetworkReachableNon:
+ case FBNetworkReachableNon:
desc = @"Not available";
break;
- case kNetworkReachableWWAN:
+ case FBNetworkReachableWWAN:
desc = @"WWAN";
break;
- case kNetworkReachableWiFi:
+ case FBNetworkReachableWiFi:
desc = @"WiFi";
break;
Please sign in to comment.
Something went wrong with that request. Please try again.