我正在尝试以编程方式使用iPhone应用程序连接wpa2企业wifi .
before that I tried connecting to that wifi manually:
-
来自iPhone设备的设置
-
使用了这三个参数SSID,用户名,密码
-
之后它要求信任证书并信任证书,wifi连接,完成!
Now I am trying to connect wifi programmatically using following code:
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”);
}
}];
but this code gives an error
无效的EAP设置:NEHotspotConfiguration EAP设置必须配置可信服务器证书或可信服务器名称
由于我没有任何可信服务器证书或可信服务器名称 . 我应该在NEHotspotEAPSettings的打击属性中设置什么(传递nil也给我同样的错误)
settings.trustedServerNames
请帮忙解决这个问题 . 谢谢!
仅供参考:在Android应用程序中工作正常,没有任何证书
1 回答
在第3步手动连接时(当它要求信任证书时)打开“更多详细信息”并尝试找出证书的“通用名称” . 它通常看起来像您的公司域名,例如“wifi.example.com” .
然后用它初始化NEHotspotEAPSettings:
如果该证书未使用iOS上安装的知名信任根,则可能无法对其进行验证,那么您可能必须使用
setTrustedServerCertificates
方法(请参阅docs - https://developer.apple.com/documentation/networkextension/nehotspoteapsettings/2875740-settrustedservercertificates?language=objc)