简体   繁体   中英

in Iphone ReachableViaWiFi is always true even though when WIFI is off

I am trying to find WIFI connection status in iphone, but it is always showing WIFI as true even though when WIFI is off. I am checking this using ReachableViaWiFi. I am not getting what is the problem?. Doing in Xcode 4.6.3

  Reachability *reachability = [Reachability reachabilityForInternetConnection];
  NetworkStatus internetStatus = [reachability currentReachabilityStatus];

  if(internetStatus==ReachableViaWiFi){  /Always only this condition is executing
  NSLog(@"Reachable VIA WIFI");
  }
  if(internetStatus==ReachableViaWWAN) {
  NSLog(@"Reachable VIA WLAN");
  }
  if(internetStatus==NotReachable){
  NSLog(@"Not Reachable");
  }

You need to write after

Reachability *reachability = [Reachability reachabilityForInternetConnection];

the next code

[reachability startNotifier];

By the way, you should to upgrade to xCode 5 if you want to upload your app to App Store or it will be rejected

Are you testing on an actual device or on the simulator? I compiled the Apple Reachability example and on the simulator TCP/IP Routing available always indicates "Reachable WiFi" regardless of the WiFi connection status. On an IPAD with both WiFi and 4G connection the code operates correctly returning either WiFi, WWAN or none.

确保将SystemConfiguration框架添加到您的构建设置中。添加框架后,按预期工作正常,我也遇到类似的问题...谢谢...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM