Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether there is internet connection with the device: cocos-2d

In one of my iPhone app, I need to find out whether there is internet connection with the device or not. Anyone pls help?

like image 767
Krishna Raj Salim Avatar asked Jan 18 '13 10:01

Krishna Raj Salim


People also ask

How do you check if there is an Internet connection?

Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top. Windows 10 lets you quickly check your network connection status.


1 Answers

Use Reachability class.

  if([self checkInternetConnected] ) 
  {
    NSLog(@"Internet connected\n");
  } 


- (BOOL)checkInternetConnected 
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];  
    NetworkStatus networkStatus = [reachability currentReachabilityStatus]; 
    return !(networkStatus == NotReachable);
}

You can get rechability class here : Download sample and add Reachability.h and Reachability.m into your project.

like image 139
Guru Avatar answered Oct 22 '22 15:10

Guru