Detect if Wi-Fi is enabled ?

Hi,


I have implemented a check in my app to test if the user is currently connected to a network using the following function:


    private func getWiFiSsid()->Bool {
        if let interfaces = CNCopySupportedInterfaces() as NSArray? {
            for interface in interfaces {
                if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
                    m_ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
                    return true;
                }
            }
        }
        return false
    }


What I need is a function that can determine if Wi-Fi is enabled. regardless if the user is connected to a network or not.


Is this possible?


Thank you in advance

Accepted Reply

Is there a third party API available that would allow this?

Any third-party API would have to be based on an Apple API, and I’ve already ruled that out.

mainly because without Wi-Fi the app would be unable to accomplish its goal of transmitting data to the device.

What device are we talking about? Another iOS device? Or some sort of Wi-Fi based accessory?

In the iOS/iOS case, there’s nothing to stop the two devices talking over Ethernet. In the iOS/Wi-Fi accessory case, that still might work if you have a Wi-Fi to Ethernet bridge (as I do on my home network).

I’m not claiming that there are no apps with this requirement, but rather my claim is that most folks who ask about this haven’t considered all the edge cases. If you can elaborate more about your specific requirements, I’m happy to discuss them, but right now you’re making a bold claim without offering any context for that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

Seen QA1942?


https://developer.apple.com/library/archive/qa/qa1942/_index.html

There is no general “Is Wi-Fi on or off?” API [1]. As to how you should proceed, that depends on your goals. What do you need this info for?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] Such an API would be trickier than you might think. In recent iOS releases we changed the behaviour of Control Center so that it doesn’t actually turn off Wi-Fi but instead disconnects from the current network and temporarily prevents the device from joining known networks. If we had shipped an “Is Wi-Fi on or off?” API prior to that, what should it return now? The correct answer depends on what you do with the results of that API, which brings us back to the question above.

  • my use case for needing wifi information is that we are developing a video streaming app and we have a setting to allow playing videos only when the wifi is connected. Now i wonder how this is acheivable without a Is Wi-Fi on or off?” API

Add a Comment

Hi eskimo,


I need to ensure W-Fi is enabled because the App will never work unless the Wi-Fi is enabled.


going to your first point. Is there a third party API available that would allow this? and also still be accepted for use on the Apple store?


Thanks

I need to ensure W-Fi is enabled because the App will never work unless the Wi-Fi is enabled.

That’s pretty bold claim. Can you explain why that’s the case?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


mainly because without Wi-Fi the app would be unable to accomplish its goal of transmitting data to the device.


I would prefer to prompt the user to enable it if its disabled


Thanks

Is there a third party API available that would allow this?

Any third-party API would have to be based on an Apple API, and I’ve already ruled that out.

mainly because without Wi-Fi the app would be unable to accomplish its goal of transmitting data to the device.

What device are we talking about? Another iOS device? Or some sort of Wi-Fi based accessory?

In the iOS/iOS case, there’s nothing to stop the two devices talking over Ethernet. In the iOS/Wi-Fi accessory case, that still might work if you have a Wi-Fi to Ethernet bridge (as I do on my home network).

I’m not claiming that there are no apps with this requirement, but rather my claim is that most folks who ask about this haven’t considered all the edge cases. If you can elaborate more about your specific requirements, I’m happy to discuss them, but right now you’re making a bold claim without offering any context for that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


its a wifi accessory but thank you for the info its much appreciated.


Thanks