I have implemented Reachability Api 2.2. When the network goes from an off state to an on state it does not fire.
In addition, can I implement it in the app delegate? If so, where should I remove observer?
Here is my code (which does not call dismiss model viewController)
- (void)viewDidLoad
{
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain] ;
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
[hostReachable startNotifier];
}
- (void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus hoststatus=[hostReachable currentReachabilityStatus];
NetworkStatus internetStatus=[internetReachable currentReachabilityStatus];
for (NSString *msg in messageArray) {
[stringg appendString:[NSString stringWithFormat:@"%@",msg]];
}
if (hoststatus==NotReachable||internetStatus==NotReachable) {
[self.navigationController presentModalViewController:inter animated:YES];
}
else{
[self dismissModalViewControllerAnimated:YES];
}
[inter release];
}
- (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super viewDidUnload];
}