Add the reachability notification in the appdelegate didFinishLaunchingWithOptions only and set the value of reachability in Bool variable isInternetAvailable in appDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkNetworkStatus:)
name:kReachabilityChangedNotification object:nil];
}
- (void)checkNetworkStatus:(NSNotification *)notice {
// called after network status changes
NetworkStatus internetStatus = [self.internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
//#######NSLog(@"The internet is down.");
self.isInternetAvailable = FALSE;
break;
}
case ReachableViaWiFi:
{
//#######NSLog(@"The internet is working via WIFI");
self.isInternetAvailable = TRUE;
break;
}
case ReachableViaWWAN:
{
//#######NSLog(@"The internet is working via WWAN!");
self.isInternetAvailable = TRUE;
break;
}
default:
{
//#######NSLog(@"The internet is working via mobile SIM!");
self.isInternetAvailable = FALSE;
break;
}
}
}