简体   繁体   中英

How can i get list of available WiFi network using CaptiveNetwork

I want to get all the WiFi networks available in a region and their SSID and SSIDDATA value. Using this I am able to get the SSID and SSIDDATA value for the WiFi network that I am using. But the problem is how to get the SSID and SSIDDATA of all the WiFi network available even if I am not connected to one. I do not want to do it using the private API like in case of stumbler as it will be rejected by AppStore. Please advice.

简单的答案是,如果不使用私有API,就无法获得它们。

I believe you might be able to through Apple's SystemConfiguration API .

This code segment from another post might be useful:

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
    }
}

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