Within iOS framework, how can one check if the Wifi radio is enabled by the user or not? Please note that I'm not interested in the reachability through Wifi but rather if the device is turned off by the user. Thanks.
-
Do you mean specifically by the user? – Ravi Oct 16 '12 at 01:07
-
see: http://stackoverflow.com/questions/1448411/how-to-check-for-local-wi-fi-not-just-cellular-connection-using-iphone-sdk – magma Oct 16 '12 at 01:09
-
1Ravi and Magma, I have an application and I need to check within the code if the user has turned off the Wifi device or whether it is left on. Correct me if I'm wrong but from my understanding Reachability gives the information of whether you can reach the internet through Wifi interface and not about its on/off state. – x89a10 Oct 16 '12 at 19:45
-
I a word - you can not. See peter's answer – Fattie Sep 21 '14 at 12:12
-
There is a hackish solution in my answer: http://stackoverflow.com/questions/29487270/detect-if-wifi-is-turned-on/29487497#29487497 – gbuzogany Apr 08 '15 at 07:46
-
You can use this code for swift, i think its work for you : https://stackoverflow.com/questions/39849755/how-to-check-if-wifi-is-on-or-off-in-ios-swift-2/45815818#45815818 – saraman Aug 22 '17 at 11:03
6 Answers
Based on: http://www.enigmaticape.com/blog/determine-wifi-enabled-ios-one-weird-trick
Wifi status can be determined to be ON/ OFF using C based ifaddress struct from:
ifaddrs.h, and
net/if.h
[Code source: unknown.]
- (BOOL) isWiFiEnabled {
NSCountedSet * cset = [NSCountedSet new];
struct ifaddrs *interfaces;
if( ! getifaddrs(&interfaces) ) {
for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) {
if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) {
[cset addObject:[NSString stringWithUTF8String:interface->ifa_name]];
}
}
}
return [cset countForObject:@"awdl0"] > 1 ? YES : NO;
}
Swift 3 version (requires bridging header with #include <ifaddrs.h>
):
func isWifiEnabled() -> Bool {
var addresses = [String]()
var ifaddr : UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ifaddr) == 0 else { return false }
guard let firstAddr = ifaddr else { return false }
for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
addresses.append(String(cString: ptr.pointee.ifa_name))
}
freeifaddrs(ifaddr)
return addresses.contains("awdl0")
}

- 5,988
- 3
- 35
- 56

- 5,045
- 1
- 18
- 28
-
1This does work! It is based on the excellent analysis at: http://www.enigmaticape.com/blog/determine-wifi-enabled-ios-one-weird-trick – mbeaty Dec 04 '14 at 10:22
-
6Note: on my iPhone 4s (iOS 8.3), this unfortunately always returns NO - regardless of the state of the Wi-Fi. – Leverin May 15 '15 at 15:17
-
Remember to call freeifaddrs on interfaces when you're finished with them. – aust Sep 16 '15 at 21:19
As mentioned in comment by @magma, you may have to use Reachability source code. So far based on my experience and what others have been talking, there is NO boolean which can tell you if the user has turned off Wi-Fi in Settings. By checking if the device can reach internet, you just have to deduce and conclude(assume) the user has turned Wi-Fi off.

- 3,190
- 1
- 25
- 49
Using Reachability is the correct way to go.
You cannot access the direct settings within an app that should go on the App Store. That is considered private user territory where an app has no reason to deal with at all.
But without more explanation I do not really see the need to find out the settings.
That is nothing an App should ever be interested or worry about. You have network access or you do not have network access. If none is available then the reason for it does not matter.
You do not ask a question like "Do you not have a Ford?" "Do you not have a BMW?". Instead from a good application design you ask "Do you have a car?"
Also Raechability has nothing to do with the Internet. It tells you if the device is theoretical reachable by over a TCP/IP network. That means some network communication is available. Then you can check what type (e.g. Wifi vs. 3G/LTE). And that is exactly what's Reachability is for.
If you for what ever reason really want to go down if the radios is turned on and it is for a kind of Enterprise app, you can look into the private frameworks, import them and deal with their undocumented methods that are subject to change with any update.
For Wifi it should be: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/PrivateFrameworks/MobileWiFi.framework

- 483
- 2
- 6
-
1Be careful when you say "no reason ... at all..." Your app might want to be courteous and only upload analytics info when it is on wifi and not use up the user's quota (not everyone in the world has an unlimited plan). You might not want to download 500 MB of optional game data over the cell network, or like Apple's AppStore app, refuse to download apps over a certain size over a cell connection. – prewett Jul 28 '15 at 20:33
-
3Another case where you may care about WiFi being on or off (and specifically is not related to external entities) is in a multi-peer connectivity environment where turning wifi on is optional but could improve the user experience measurably. – Brad Brighton Aug 06 '15 at 04:29
-
1Another reason to want to know if WiFi is on or off is if you are monitoring geographic regions. The entry/exit events are much more timely and accurate if wifi is turned on. In the case of small regions, without wifi, the region can be completely missed and no events generated. In the case Wifi is off, you may choose to keep using GPS directly to detect the region. – BitByteDog Oct 06 '15 at 03:20
-
@BradBrighton I think having either WiFi or Bluetooth turned on is mandatory for Multipeer Connectivity to work. – SayeedHussain Mar 10 '16 at 10:48
-
@paranoidcoder One or the other, correct. And in the general case, MPC is meant to be opaque as to which one, to the developer's benefit. However, there are certain configuration or data reduction actions that might make sense if BT is on and wifi is off, due to the lower bandwidth. – Brad Brighton Mar 10 '16 at 12:27
-
Too ultimate statement. My app is tracking location and it's important to me to know is WiFi enabled or not. – AlexeyVMP Jul 30 '18 at 17:48
iOS has no public API that tells you if Wi-Fi is on or off.
However, you can use the public API CNCopyCurrentNetworkInfo()
, available in SystemConfiguration framework, to get info about the current Wi-Fi network. This does not tell you if Wi-Fi is turned on or off but rather if the device is joined to a Wi-Fi network or not. Perhaps this is sufficient for your purposes.
Also note that this API doesn't work in Simulator, as CNCopySupportedInterfaces()
always returns NULL.
#include <SystemConfiguration/CaptiveNetwork.h>
BOOL hasWiFiNetwork = NO;
NSArray *interfaces = CFBridgingRelease(CNCopySupportedInterfaces());
for (NSString *interface in interfaces) {
NSDictionary *networkInfo = CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interface)));
if (networkInfo != NULL) {
hasWiFiNetwork = YES;
break;
}
}

- 20,354
- 10
- 69
- 64
Swift 2.3 version
func isWifiEnabled() -> Bool {
var addresses = [String]()
var ifaddr : UnsafeMutablePointer<ifaddrs> = nil
guard getifaddrs(&ifaddr) == 0 else { return false }
var ptr = ifaddr
while ptr != nil { defer { ptr = ptr.memory.ifa_next }
addresses.append(String.fromCString(ptr.memory.ifa_name)!)
}
var counts:[String:Int] = [:]
for item in addresses {
counts[item] = (counts[item] ?? 0) + 1
}
freeifaddrs(ifaddr)
return counts["awdl0"] > 1 ? true : false
}
Swift 4.0 version
func isWifiEnabled() -> Bool {
var addresses = [String]()
var ifaddr : UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ifaddr) == 0 else { return false }
guard let firstAddr = ifaddr else { return false }
for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
addresses.append(String(cString: ptr.pointee.ifa_name))
}
var counts:[String:Int] = [:]
for item in addresses {
counts[item] = (counts[item] ?? 0) + 1
}
freeifaddrs(ifaddr)
guard let count = counts["awdl0"] else { return false }
return count > 1
}

- 7,498
- 15
- 65
- 88

- 5,001
- 14
- 58
- 117
PrivateFrameworks is not available in sdk nor is it available to any enterprise developer.
If we know what you want to achieve my knowing the wifi radio power state, we can probably suggest an alternative solution, but from how apple has been with what they expose to developers i don't see this ever becoming possible directly.
Using reachability you can know for sure if wifi is ON but to know if wifi is OFF toss a coin.

- 532
- 4
- 12