如何确定个人热点是否处于活动状态? 我尝试过:
@objc
func getCurrentNetwork(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock)
{
var networkDict = [String : Any]()
let deviceName = UIDevice.current.name
print("device name: \(deviceName)")
guard let interfaces = CNCopySupportedInterfaces() as? [String] else {
reject("ios_errors", "Can't work on simulators", nil)
return
}
for interface in interfaces {
print("Looking up SSID info for \(interface)")
guard let interfaceInfo = CNCopyCurrentNetworkInfo(interface as CFString) else {
print("System error: \(interface) has no information") <- here
return
}
guard let networkInfo = (interfaceInfo as NSDictionary) as? [String: AnyObject] else {
print("System error: interface information is not a string-keyed dictionary")
return
}
for key in networkInfo.keys {
networkDict["\(key)"] = "\(networkInfo[key]!)"
}
}
resolve(networkDict)
}
当iPhone连接到公共热点时,以上示例将SSID名称(以及其他信息)返回给客户端。 当我激活iPhone的个人热点时,我输入以下代码行:
print("System error: \(interface) has no information")
return
并返回客户而不得到热点的名称?
我在这里查看了2个选项:
172.20.10
开头,则意味着个人热点已激活并且设备已连接至该设备,我可以返回设备名称作为SSID名称,但是这个问题不是很牢固,还是我错了?