I modified apple's reachability class to use with my server ip. But when I use reachabilityWithAddress
it's not called reachabilityChanged
while app is launching. It is called only internet connection status changed. ( like turning wi-fi off, on ) But, if I use reachabilityWithHostName
, reachabilityChanged
function called when app is launching.
What am I missing?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
///////////////////////////////////////////////////////////////////////////////////
// Reachability Local Notifications
///////////////////////////////////////////////////////////////////////////////////
hasInternetConnection = NO;
struct sockaddr_in address;
address.sin_len = sizeof(address);
address.sin_family = AF_INET;
address.sin_port = htons(80);
address.sin_addr.s_addr = inet_addr("X.X.X.X");
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil];
hostReach = [Reachability reachabilityWithAddress:&address];
[hostReach startNotifier];
...
}
Then in method:
-(void)reachabilityChanged:(NSNotification*)note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
if ( curReach == hostReach ) {
NetworkStatus netStatus = [curReach currentReachabilityStatus];
if ( netStatus != ReachableViaWiFi && netStatus != ReachableViaWWAN ) {
hasInternetConnection = NO;
}
else {
hasInternetConnection = YES;
}
}
else {
DLog(@"Something go wrong!");
}
}