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

半世苍凉 提交于 2019-12-31 22:26:46

问题


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:


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.



来源:https://stackoverflow.com/questions/14397054/how-to-check-whether-there-is-internet-connection-with-the-device-cocos-2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!