nehelper为Wi-Fi信息请求发送了无效的结果代码[1]
nehelper sent invalid result code [1] for Wi-Fi information request
//获取wifi名称
func getUsedSSID() -> String {
var currentSSID = ""
if let interfaces:CFArray = CNCopySupportedInterfaces() {
for i in 0..<CFArrayGetCount(interfaces){
let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interfaces, i)
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString)
if unsafeInterfaceData != nil {
let interfaceData = unsafeInterfaceData! as! Dictionary<String, Any>
currentSSID = interfaceData["SSID"] as! String
}
else{
print("data nil")
}
}
}
print(currentSSID)
return currentSSID
}
解决方案1
增加访问权限
添加 Capability -> Accesss WiFi Infomation
解决方案2
增加一个获取地理位置权限
import CoreLocation//导入位置包
CLLocationManagerDelegate//在vc里增加一个地理位置管理器代理
var locationManager:CLLocationManager?//定义一个地理管理器
//在viewDidLoad里输入代码
self.locationManager = CLLocationManager()
self.locationManager?.delegate = self
self.locationManager?.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager?.distanceFilter = 1000.0
self.locationManager?.requestWhenInUseAuthorization()
self.locationManager?.requestAlwaysAuthorization()
self.locationManager?.startUpdatingLocation()
info.plist文件添加
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>AlwaysAndWhenInUseUsageDescription</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>AlwaysUsageDescription</string>
<key>NSLocationUsageDescription</key>
<string>UsageDescription</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>WhenInUseUsageDescription</string>