ios iPhone 获取没有私人图书馆的所有 SSID 的列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9684341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone get a list of all SSIDs without private library
提问by grubernd
Is it possible the get a listof all available SSIDs on the iPhone without using a private library?
是否有可能在不使用私人图书馆的情况下获得 iPhone 上所有可用 SSID的列表?
I read iPhone get SSID without private librarywhich is about getting details about the currentnetwork.
我读过iPhone get SSID without private library这是关于获取有关当前网络的详细信息。
This answermentions:
这个答案提到:
If you jailbreak your device you can use the Apple80211private framework to look up the available Wi-Fi networks and their signal strength. But that also means your app will get rejected.
如果您越狱了您的设备,您可以使用Apple80211私有框架来查找可用的 Wi-Fi 网络及其信号强度。但这也意味着您的应用将被拒绝。
Apple has the CaptiveNetwork APIbut there doesn't seem to be a solution to get a list of all available networks. It seems it's only possible to do so with using the Apple80211 private library, or connecting to all of them.
Apple 有CaptiveNetwork API,但似乎没有解决方案可以获取所有可用网络的列表。似乎只有使用Apple80211 private library或连接到所有这些库才能做到这一点。
Am I missing something, or is there no solution?
我错过了什么,还是没有解决方案?
采纳答案by Rok Jarc
Without the use of private library (Apple80211
) you can only get the SSID of the network your device is currently connected to.
在不使用私有库 ( Apple80211
) 的情况下,您只能获取设备当前连接到的网络的 SSID。
回答by cwliang
Since iOS 9, you can use NEHotspotHelperto get a list of SSIDs. But you have to get the com.apple.developer.networking.HotspotHelper
entitlement from Apple by sending a request.
从 iOS 9 开始,您可以使用NEHotspotHelper来获取 SSID 列表。但是您必须com.apple.developer.networking.HotspotHelper
通过发送请求从 Apple获得授权。
Check https://developer.apple.com/documentation/networkextension/nehotspothelperfor more infomation.
检查https://developer.apple.com/documentation/networkextension/nehotspothelper了解更多信息。
回答by Senseful
Some new APIs have been released as part of the Network Extension in iOS 9 and iOS 11. While neither allows you to scan for networks while your app is running, they both allow you to do related tasks. E.g. you can scan for networks while the Settings Wi-Fi page is running using Hotspot Helper, and you can make it easier for a user to join a network using either of these.
一些新的 API 已经作为 iOS 9 和 iOS 11 中网络扩展的一部分发布。虽然它们都不允许您在应用程序运行时扫描网络,但它们都允许您执行相关任务。例如,您可以在“设置 Wi-Fi”页面运行时使用 Hotspot Helper 扫描网络,并且您可以使用户更轻松地使用其中任何一个加入网络。
Here's a comparison of the two frameworks.
这是两个框架的比较。
Hotspot Helper
热点助手
NEHotspotHelper
(introduced in iOS 9, WWDC 2015).- Requires special permission from Apple.
- Requires the
com.apple.developer.networking.HotspotHelper
entitlement. - For step-by-step instructions to get this working, see this answer.
Allows you to participate in the discovery/authentication to a Wi-Fi network via the Wi-Fi screen in the Settings app.You register to be notified when networks are being scanned (e.g. when the user launches Wi-Fi in the Settings app), and you can automatically pre-fill the password and display an annotation near the network name. The user still needs to tap on the network name to connect, but it won't prompt for a password if you pre-filled it.
NEHotspotHelper
(在 iOS 9、WWDC 2015 中引入)。- 需要 Apple 的特别许可。
- 需要
com.apple.developer.networking.HotspotHelper
权限。 - 有关使其工作的分步说明,请参阅此答案。
允许您通过“设置”应用程序中的 Wi-Fi 屏幕参与 Wi-Fi 网络的发现/验证。您注册以在网络被扫描时收到通知(例如,当用户在“设置”应用程序中启动 Wi-Fi 时),您可以自动预填密码并在网络名称附近显示注释。用户仍然需要点击网络名称才能连接,但如果您预先填写密码,则不会提示输入密码。
Hotspot Configuration
热点配置
NEHotspotConfigurationManager
(introduced in iOS 11, WWDC 2017).- Does not require special permission from Apple.
- Requires the
com.apple.developer.networking.HotspotConfiguration
entitlement. Allows you to initiate a connection to a Wi-Fi network.You give it a list of SSIDs/Passwords that should be connected to while your app is running. It will present a dialog asking the user if they want to connect to the network.
NEHotspotConfigurationManager
(在 iOS 11、WWDC 2017 中引入)。- 不需要 Apple 的特别许可。
- 需要
com.apple.developer.networking.HotspotConfiguration
权限。 允许您启动与 Wi-Fi 网络的连接。你给它一个在你的应用程序运行时应该连接到的 SSID/密码列表。它将显示一个对话框,询问用户是否要连接到网络。
回答by Sarvesh Singh
Step 1:add the framework SystemConfiguration.framework
Step 2:import following header file
第一步:添加框架SystemConfiguration.framework
第二步:导入如下头文件
import SystemConfiguration
import SystemConfiguration.CaptiveNetwork
Step 3:Now Use Code:
第 3 步:现在使用代码:
func getUsedSSID()->String {
let interfaces = CNCopySupportedInterfaces()
if interfaces != nil {
let interfacesArray = CFBridgingRetain(interfaces) as! NSArray
if interfacesArray.count > 0 {
let interfaceName = interfacesArray[0] as! String
let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)! as Dictionary
let SSIDName = unsafeInterfaceData["SSID"] as! String
print(SSIDName)/* here print recentally used wifi name*/
return SSIDName
}else{
return "0"
}
}else{
return "0"
}
}
回答by Sarvesh Singh
First of All import above two system Header file
首先导入上面两个系统头文件
import SystemConfiguration/SystemConfiguration.h
import SystemConfiguration/CaptiveNetwork.h
below Function/Method Return SSIDName
下面的函数/方法返回 SSIDName
-(NSString *)getNetworkId{
NSString *string = CFBridgingRelease(CNCopySupportedInterfaces());
NSArray *interfacesArray = CFBridgingRelease(CFBridgingRetain(string));
if(interfacesArray.count > 0){
NSString *networkName = [interfacesArray objectAtIndex:0];
CFStringRef yourFriendlyCFString = (__bridge CFStringRef)networkName;
NSDictionary *unsafeInterfaceData = CFBridgingRelease(CNCopyCurrentNetworkInfo(yourFriendlyCFString));
NSString *ssidName = unsafeInterfaceData[@"SSID"];
return ssidName;
}
return @"No network Found";
}
回答by Sarvesh Singh
#import SystemConfiguration#
##import SystemConfiguration.CaptiveNetwork##
//create variable
var SSIDNameArray = NSMutableArray()
var nameArray : NSArray = [];
// Here function to return all SSIDName
func getUsedSSID()->NSArray{
let interfaces = CNCopySupportedInterfaces()
if interfaces != nil {
let interfacesArray = CFBridgingRetain(interfaces) as! NSArray
if interfacesArray.count > 0 {
for interfaceName in interfacesArray {
let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName as! CFString)! as NSDictionary
let SSIDName = unsafeInterfaceData["SSID"] as! String
self.SSIDNameArray .add(SSIDName)
}
nameArray = self.SSIDNameArray .copy() as! NSArray
return nameArray;
}else{
return nameArray;
}
}else{
return nameArray;
}
}