First Download Reachability classes from this Link:
Rechability from Github
Add Instance of Reachability in AppDelegate.h
@property (nonatomic) Reachability *hostReachability;
@property (nonatomic) Reachability *internetReachability;
@property (nonatomic) Reachability *wifiReachability;
Import Reachability in your AppDelegate and just copy and past this code in your Appdelegate.m
- (id)init
{
self = [super init];
if (self != nil)
{
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
NSString *remoteHostName = @"www.google.com";
self.hostReachability = [Reachability reachabilityWithHostName:remoteHostName];
[self.hostReachability startNotifier];
self.internetReachability = [Reachability reachabilityForInternetConnection];
[self.internetReachability startNotifier];
self.wifiReachability = [Reachability reachabilityForLocalWiFi];
[self.wifiReachability startNotifier];
}
return self;
}
Add this method in your Common Class.
/*================================================================================================
Check Internet Rechability
=================================================================================================*/
+(BOOL)checkIfInternetIsAvailable
{
BOOL reachable = NO;
NetworkStatus netStatus = [APP_DELEGATE1.internetReachability currentReachabilityStatus];
if(netStatus == ReachableViaWWAN || netStatus == ReachableViaWiFi)
{
reachable = YES;
}
else
{
reachable = NO;
}
return reachable;
}
Note that APP_DELEGATE1 Is an instance of AppDelegate
/* AppDelegate object */
#define APP_DELEGATE1 ((AppDelegate*)[[UIApplication sharedApplication] delegate])
You can check internet connectivity anywhere in app using this method.