22

I want to get all the WiFi networks available in a region and their SSID value. But the problem is how to get the SSID of all the WiFi network available even if I am not connected to one.

4
  • @EnricoSusatyo i have same problem i can't have get all available wifi list. Commented Aug 17, 2016 at 12:13
  • Not easily. Scanning wifi networks is a security threat. Commented Jan 27, 2017 at 21:08
  • 4
    I found similar questions asked on SO with a quick google search, the common answer is that while you can you are not supposed to due to Apples rules Commented Jan 28, 2017 at 4:45
  • yeah I found one similar question here stackoverflow.com/questions/5198716/… Commented Feb 3, 2017 at 10:22

3 Answers 3

17
+50

iOS 12

You must enable Access WiFi Information from capabilities.

Important To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID. Documentation link

First;

import SystemConfiguration.CaptiveNetwork

Then;

 func getInterfaces() -> Bool {
    guard let unwrappedCFArrayInterfaces = CNCopySupportedInterfaces() else {
        print("this must be a simulator, no interfaces found")
        return false
    }
    guard let swiftInterfaces = (unwrappedCFArrayInterfaces as NSArray) as? [String] else {
        print("System error: did not come back as array of Strings")
        return false
    }
    for interface in swiftInterfaces {
        print("Looking up SSID info for \(interface)") // en0
        guard let unwrappedCFDictionaryForInterface = CNCopyCurrentNetworkInfo(interface) else {
            print("System error: \(interface) has no information")
            return false
        }
        guard let SSIDDict = (unwrappedCFDictionaryForInterface as NSDictionary) as? [String: AnyObject] else {
            print("System error: interface information is not a string-keyed dictionary")
            return false
        }
        for d in SSIDDict.keys {
            print("\(d): \(SSIDDict[d]!)")
        }
    }
    return true
}
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to only return the currently connected wifi at least on iOS 11.2.2 on an iPhone 7
0

Here my class that prints the WIFI network name

import UIKit
import Foundation
import SystemConfiguration.CaptiveNetwork

class FirstView: UIViewController
{
    @IBOutlet weak var label: UILabel!

    override func viewDidLoad()
    {
        super.viewDidLoad()
        let ssid = self.getWiFiName()
        print("SSID: \(ssid)")
    }

    func getWiFiName() -> String? {
        var ssid: String?
        if let interfaces = CNCopySupportedInterfaces() as NSArray? {
            for interface in interfaces {
                if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
                    ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
                    break
                }
            }
        }
        return ssid
    }
}

2 Comments

This only seems to show the connected interface SSID.
var ssid = ""; (CNCopySupportedInterfaces() as? [CFString])?.forEach({ ssid = (CNCopyCurrentNetworkInfo($0) as? [String : Any])?[kCNNetworkInfoKeySSID as String] as? String ?? ""})
0

Yes it is possible to list all nearby WiFi networks.You need to complete a questionnaire at https://developer.apple.com/contact/network-extension, and then you can use NEHotspotHelper to return a list of hotspots. Technical Q&A https://developer.apple.com/library/archive/qa/qa1942/_index.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.