iPhone获得没有私人图书馆的SSID [英] iPhone get SSID without private library

查看:116
本文介绍了iPhone获得没有私人图书馆的SSID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个商业应用程序有一个完全正当的理由看到它所连接的网络的SSID:如果它连接到第三方硬件设备的Adhoc网络,它需要以不同于如果它连接到互联网。

I have a commercial app that has a completely legitimate reason to see the SSID of the network it is connected to: If it is connected to a Adhoc network for a 3rd party hardware device it needs to be functioning in a different manner than if it is connected to the internet.

我所看到的关于获取SSID的所有信息都告诉我,我必须使用Apple80211,我知道这是一个私人图书馆。我还读到,如果我使用私人图书馆,Apple将不会批准该应用程序。

Everything I've seen about getting the SSID tells me I have to use Apple80211, which I understand is a private library. I also read that if I use a private library Apple will not approve the app.

我是不是在苹果和硬地之间,或者是我有什么东西在这里缺少?

Am I stuck between an Apple and a hard place, or is there something I'm missing here?

推荐答案

从iOS 7或8开始,你可以这样做,它利用了ARC和模块,自动链接到所需的框架:

As of iOS 7 or 8, you can do this, which takes advantage of ARC and modules, which will automatically link in the needed framework:

@import SystemConfiguration.CaptiveNetwork;

/** Returns first non-empty SSID network info dictionary.
 *  @see CNCopyCurrentNetworkInfo */
- (NSDictionary *)fetchSSIDInfo
{
    NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
    NSLog(@"%s: Supported interfaces: %@", __func__, interfaceNames);

    NSDictionary *SSIDInfo;
    for (NSString *interfaceName in interfaceNames) {
        SSIDInfo = CFBridgingRelease(
            CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
        NSLog(@"%s: %@ => %@", __func__, interfaceName, SSIDInfo);

        BOOL isNotEmpty = (SSIDInfo.count > 0);
        if (isNotEmpty) {
            break;
        }
    }
    return SSIDInfo;
}

(这是为iOS 4.1+编写的代码示例的现代化。只有更改才会引入更清晰的变量名称并采用ARC和模块。)

(This is a modernization of a code sample written for iOS 4.1+. The only changes were introducing clearer variable names and adopting ARC and modules.)

示例输出:

2011-03-04 15:32:00.669 ShowSSID[4857:307] -[ShowSSIDAppDelegate fetchSSIDInfo]: Supported interfaces: (
    en0
)
2011-03-04 15:32:00.693 ShowSSID[4857:307] -[ShowSSIDAppDelegate fetchSSIDInfo]: en0 => {
    BSSID = "ca:fe:ca:fe:ca:fe";
    SSID = XXXX;
    SSIDDATA = <01234567 01234567 01234567>;
}

请注意,模拟器上不支持ifs。在您的设备上进行测试。

Note that no ifs are supported on the simulator. Test on your device.

在4.1之前,您可能会通过系统配置字典获得一些运气。例如,在我的Mac上使用 scutil

Prior to 4.1, you might have some luck spelunking through the System Configuration dictionary. For example, using scutil on my Mac:

$ scutil
> show State:/Network/Interface/en1/AirPort
<dictionary> {
  Power Status : 1
  SecureIBSSEnabled : FALSE
  BSSID : <data> 0xcafecafecafe
  SSID_STR : XXXX
  SSID : <data> 0x012345670123456701234567
  Busy : FALSE
  CHANNEL : <dictionary> {
    CHANNEL : 1
    CHANNEL_FLAGS : 10
  }
}
> exit

这篇关于iPhone获得没有私人图书馆的SSID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆