Please follow this steps,
1>make property of Reachability and NetworkStatus;
in your appDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>{
Reachability* reachability;
NetworkStatus remoteHostStatus;
}
@end
2>Create Notification method when reachability changed in applicationDidBecomeActive
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
remoteHostStatus = [reachability currentReachabilityStatus];
if(remoteHostStatus == NotReachable) {
if(DEBUG_MODE){NSLog(@"no");}
}
else if (remoteHostStatus == ReachableViaWiFi) {if(DEBUG_MODE)
{NSLog(@"wifi");}
}
else if (remoteHostStatus == ReachableViaWWAN) {if(DEBUG_MODE){NSLog(@"cell");}
}
}
3> declare reachabilityChanged
-(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
{
if([self isReachableWithFlags:flags])
{
if(self.reachableBlock)
{
self.reachableBlock(self);
}
}
else
{
if(self.unreachableBlock)
{
self.unreachableBlock(self);
}
}
// this makes sure the change notification happens on the MAIN THREAD
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification
object:self];
});
}
Thanks.