获取个人热点状态(将由Apple批准)

时间:2019-02-25 11:34:27

标签: ios swift networking personal-hotspot

如何确定个人热点是否处于活动状态? 我尝试过:

    @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个选项:

  1. detect hotspot enabling in iOS with private api's-私有api对我不好,因为我想将我的应用程序放在Apple商店中。
  2. Swift - Get device's WIFI IP Address-通过这种方法,我想获取设备的wifi ip地址,如果它以172.20.10开头,则意味着个人热点已激活并且设备已连接至该设备,我可以返回设备名称作为SSID名称,但是这个问题不是很牢固,还是我错了?

0 个答案:

没有答案