Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use this code to check whether the device is connected to internet or not</p> <p>use this code in viewDidLoad :</p> <pre><code> Reachability* internetReachable; = [Reachability reachabilityForInternetConnection]; [internetReachable startNotifier]; hostReachable = [Reachability reachabilityWithHostName: @"www.apple.com"] ; [hostReachable startNotifier]; </code></pre> <p>and add this function to your code:</p> <pre><code>-(void) checkNetworkStatus:(NSNotification *)notice { recheabilityBool=FALSE; nonrecheabilityBool=FALSE; // called after network status changes NetworkStatus internetStatus = [internetReachable currentReachabilityStatus]; switch (internetStatus) { case NotReachable: { nonrecheabilityBool=TRUE; internetCon=0; //NSLog(@"The internet is down."); break; } case ReachableViaWiFi: { NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; internetCon=404; [prefs setInteger:internetCon forKey:@"conKey"]; //NSLog(@"The internet is working via WIFI."); break; } case ReachableViaWWAN: { //NSLog(@"The internet is working via WWAN."); break; } } NetworkStatus hostStatus = [hostReachable currentReachabilityStatus]; switch (hostStatus) { case NotReachable: { internetCon=0; if( nonrecheabilityBool==FALSE) { //NSLog(@"A gateway to the host server is down."); } break; } case ReachableViaWiFi: { if(recheabilityBool==FALSE) { recheabilityBool=TRUE; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; internetCon=404; [prefs setInteger:internetCon forKey:@"conKey"]; //NSLog(@"The internet is working via WIFI."); break; } //NSLog(@"A gateway to the host server is working via WIFI."); break; } case ReachableViaWWAN: { //NSLog(@"A gateway to the host server is working via WWAN."); break; } } } - (BOOL)connected { Reachability *reachability = [Reachability reachabilityForInternetConnection]; NetworkStatus networkStatus = [reachability currentReachabilityStatus]; return !(networkStatus == NotReachable); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload