简体   繁体   English

如何在Mac应用程序中检索Wi-Fi热点列表?

[英]How can I retrieve list of Wi-Fi hotspots in Mac application?

I need to programatically retrieve a list of nearest Wi-Fi hotspots(preferably using swift, but if it's not possible, objective-c will do) and I just don't get how can I do it. 我需要以编程方式检索最近的Wi-Fi热点列表(最好使用swift,但如果不可能,objective-c会这样做),但我不知道该怎么做。 I have tried to search for samples, but the only one I found is outdated and doesn't run on Xcode 6.3 . 我尝试搜索示例,但是我发现的唯一示例已经过时并且不能在Xcode 6.3上运行。 Any help will be great. 任何帮助都会很棒。

I'm now trying to use Swift code below, but it's not working, any tips? 我现在正尝试在下面使用Swift代码,但没有任何提示?

var ind = CWInterface()

@IBAction func doer(sender: AnyObject) {

    var network:CWNetwork?
   var networks = ind.scanForNetworksWithName(nil, error: nil)
    for network in networks
   {
        print(network)
    }

You can check out and update the Apple project from here (that you probably mentioned) with the help of this link to the current interfaces that apple exposes. 您可以从此处 (您可能提到过)从此处签出并更新Apple项目,此链接指向 Apple公开的当前接口。

For example instead of using kCWPHYMode11A you use kCWPHYMode11a , instead of using kCWSecurityModeWEP you use kCWSecurityWEP . 例如,而不是使用kCWPHYMode11A您使用kCWPHYMode11a ,而不是使用kCWSecurityModeWEP您使用kCWSecurityWEP Try changing these two, then go to the definition of kCWSecurityModeWEP and, you'll see in the header all the corresponding elements that changed, thankfully you they have descriptive names so it's kind of straight forward to match. 尝试更改这两个元素,然后转到kCWSecurityModeWEP的定义,您将在标头中看到所有已更改的相应元素,幸运的是,它们具有描述性名称,因此很容易匹配。 Keep in mind that some enums may have changed - like CWSecurity , so you need to search a little for the developer notes on these changes. 请记住,某些枚举可能已更改,例如CWSecurity ,因此您需要搜索一些有关这些更改的开发人员说明。

After some more googling and reading forums I realized what caused my Swift code to crash the app and I fixed the bug, here's working example: 经过更多的谷歌搜索和阅读论坛后,我意识到是什么导致我的Swift代码使应用程序崩溃并修复了该错误,这是一个有效的示例:

var cwInterface: CWInterface = CWInterface(name: "en1")
    var netArray:[CWNetwork]=[]
    var testArray:[String]=[]
netArray = Array(cwInterface.scanForNetworksWithName(nil , error: nil)) as! [CWNetwork]
        var network=netArray[0]
        for network in netArray
        {
            testArray.append(network.ssid)
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM