0

I am using my app and Internet connection is disable. Next, I am going to enable my Internet connection. Now how can I find that my Internet connection is enabled or not without doing anything in my app?

I am working in obj-c.

Kacper Madej
  • 7,566
  • 19
  • 32

2 Answers2

0

import Reachability.h file from here and do like following:

if ([[Reachability reachabilityForInternetConnection]currentReachabilityStatus]==NotReachable)
    {
         //Do here what you want to do when connection unavailable
    }
    else
    {
         //Do here what you want to do when connection available
    }
Suraj Sukale
  • 1,696
  • 1
  • 9
  • 18
0

Use this method

+(BOOL)isNetAvailable
{
  CFNetDiagnosticRef dReference;
  dReference = CFNetDiagnosticCreateWithURL (NULL, (__bridge CFURLRef)[NSURL URLWithString:@"www.apple.com"]);

  CFNetDiagnosticStatus status;
  status = CFNetDiagnosticCopyNetworkStatusPassively (dReference, NULL);

  CFRelease (dReference);

  if ( status == kCFNetDiagnosticConnectionUp )
  {
      NSLog (@"Connection is Available");
      return YES;
  }
  else
  {
      NSLog (@"Connection is down");
      return NO;
  }
}
Akash KR
  • 718
  • 3
  • 10