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

前端 未结 1 1511
北恋
北恋 2021-02-06 02:52

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

1条回答
  •  花落未央
    2021-02-06 03:08

    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.

    0 讨论(0)
提交回复
热议问题