【问题标题】:Connect WPA2 Enterprise wifi programmatically以编程方式连接 WPA2 Enterprise wifi
【发布时间】:2018-08-18 17:44:28
【问题描述】:

我正在尝试以编程方式使用 iPhone 应用程序连接 wpa2 企业 wifi。

在此之前我尝试手动连接到该 wifi:

  1. 从 iPhone 设备中的设置
  2. 使用了SSID、用户名、密码这三个参数
  3. 请求信任证书并信任证书后,wifi 连接,完成!

现在我正在尝试使用以下代码以编程方式连接 wifi:

NEHotspotEAPSettings *settings = [[NEHotspotEAPSettings alloc]init];
settings.password = self.password.text;
settings.username = self.username.text;
settings.supportedEAPTypes = [NSArray arrayWithObjects:[NSNumber numberWithInteger:NEHotspotConfigurationEAPTypeEAPPEAP], nil];
NEHotspotConfiguration *configuration = [[NEHotspotConfiguration alloc]initWithSSID:self.ssid.text eapSettings:settings];
[[NEHotspotConfigurationManager sharedManager]applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) {
if (error) { 
NSLog(@"Error: %@",error.localizedDescription);
} else {
NSLog(@“Connected”);
}
}];

但是这段代码出错了

无效的 EAP 设置: NEHotspotConfiguration EAP 设置必须配置受信任的服务器证书或受信任的服务器名称

因为我没有任何受信任的服务器证书或受信任的服务器名称。 我应该在 NEHotspotEAPSettings 的 blow 属性中设置什么(传递 nil 也会给我同样的错误)

settings.trustedServerNames 

请帮助解决这个问题。 谢谢!

仅供参考:在没有任何证书的情况下,在 android 应用中运行良好

【问题讨论】:

  • 这个问题你解决了吗?我们有同样的问题。

标签: ios objective-c wifi connect


【解决方案1】:

在第 3 步手动连接时(当它要求信任证书时)打开“更多详细信息”并尝试找出证书的“通用名称”。它通常看起来像您的公司域名,例如“wifi.example.com”。

然后用它初始化NEHotspotEAPSettings:

settings.trustedServerNames = @[ "wifi.example.com" ];

如果该证书未使用安装在 iOS 上的知名信任根,它可能无法验证它,那么您可能必须改用 setTrustedServerCertificates 方法(请参阅文档 - https://developer.apple.com/documentation/networkextension/nehotspoteapsettings/2875740-settrustedservercertificates?language=objc

【讨论】:

    猜你喜欢
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2017-06-25
    • 2013-04-30
    • 1970-01-01
    相关资源
    最近更新 更多