美文网首页
iOS13获取wifi信息(BSSID)

iOS13获取wifi信息(BSSID)

作者: 商山夜行人 | 来源:发表于2020-05-26 13:23 被阅读0次
    lazy var locationManager: CLLocationManager = {
        let manager = CLLocationManager()
        manager.delegate = self
        switch CLLocationManager.authorizationStatus() {
        case .notDetermined:
            // Request when-in-use authorization initially
            manager.requestWhenInUseAuthorization()
            break
        case .restricted, .denied:
            // Disable location features
            break
        case .authorizedWhenInUse, .authorizedAlways:
            // Enable location features
            break
        default:
            break
        }
        return manager
    }()
    
    //获取 WiFi 信息
    func getWifiInfo() -> (ssid: String, mac: String) {
        locationManager.requestWhenInUseAuthorization()
        if let cfas: NSArray = CNCopySupportedInterfaces() {
            for cfa in cfas {
                if let dict = CFBridgingRetain(CNCopyCurrentNetworkInfo(cfa as! CFString)) {
                    print(dict)
                    if let ssid = dict["SSID"] as? String, let bssid = dict["BSSID"] as? String {
                        return (ssid, bssid)
                    }
                }
            }
        }
        return ("未知", "未知")
    }

    相关文章

      网友评论

          本文标题:iOS13获取wifi信息(BSSID)

          本文链接:https://www.haomeiwen.com/subject/vbpxjctx.html