`
java-mans
  • 浏览: 11437736 次
文章分类
社区版块
存档分类
最新评论

判断Iphone,Ipad当前网络状态

 
阅读更多

1、到苹果管网下载Reachability的Demo,https://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

然后把:Reachability.h 和Reachability.m 添加到工程中


2、使用如下方法就能判断当前是否联网:

bool CCNetworkConfig::isNetworkAvailable()

{

Reachability *r = [ReachabilityreachabilityWithHostName:@"www.apple.com"];

switch ([rcurrentReachabilityStatus]) {

caseReachableViaWWAN: // 使用3G网络

printf("current network 3g/gprs\n");

return true;

caseReachableViaWiFi: // 使用WiFi网络

printf("current network wifi\n");

return true;

caseNotReachable: // 没有网络连接

default:

break;

}

printf("current network none\n");

return false;

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics