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 ("未知", "未知")
}
网友评论