You can use a NSTimer and in that timer you can call a BOOL function of Reachability class after every 2 seconds and make it repeat YES which returns true of false
NSTimer* internetTimer;
internetTimer=[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(checkInternet) userInfo:nil repeats:YES];
-(void)checkInternet{
if([self isInternetAvailable])
{
//enable button
}
else
{
//disable button
}
}
-(BOOL)isInternetAvailable()
{
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
return !(networkStatus == NotReachable);
}
You can find Reachability class .h and .m here. Just add the both files in your project.
https://github.com/tonymillion/Reachability
If you are in ARC on mode, may be you have to set the fno flags also for the .m
You can also add a reachability observer somewhere (i.e. in viewDidLoad):
Reachability *reachabilityInfo;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myReachabilityDidChangedMethod)
name:kReachabilityChangedNotification
object:reachabilityInfo];