问题描述
我有一个商业应用程序,它有一个完全合法的理由来查看它所连接网络的 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.
我是被困在 Apple 和困难的地方之间,还是我在这里遗漏了什么?
Am I stuck between an Apple and a hard place, or is there something I'm missing here?
推荐答案
从 iOS 7 或 8 开始,您可以这样做(需要 iOS 12+ 的 Entitlement,如下所示):
As of iOS 7 or 8, you can do this (need Entitlement for iOS 12+ as shown below):
@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;
}
示例输出:
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.
您必须从功能中启用访问 wifi 信息.
You must enable access wifi info from capabilities.
重要要在 iOS 12 及更高版本中使用此功能,请在 Xcode 中为您的应用启用访问 WiFi 信息功能.当您启用此功能时,Xcode 会自动将 Access WiFi Information 权利添加到您的权利文件和 App ID.文档链接
Swift 4.2
func getConnectedWifiInfo() -> [AnyHashable: Any]? {
if let ifs = CFBridgingRetain( CNCopySupportedInterfaces()) as? [String],
let ifName = ifs.first as CFString?,
let info = CFBridgingRetain( CNCopyCurrentNetworkInfo((ifName))) as? [AnyHashable: Any] {
return info
}
return nil
}
这篇关于iPhone在没有私人图书馆的情况下获得SSID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!