我正在尝试在我的应用程序上安装VPN,问题是在安装后,IOS会提示我输入VPN的密码,即使它已在代码中指定。
我的代码出了什么问题?
@IBAction func Install(_ sender: Any) {
NEVPNManager.shared().loadFromPreferences { error in
// setup the config:
let password = "vpnpass"
let vpnhost = "us-west.windscribe.com"
let p = NEVPNProtocolIKEv2()
p.username = "vpnuser"
p.serverAddress = vpnhost
p.remoteIdentifier = vpnhost
p.authenticationMethod = .none
p.passwordReference = password.data(using: .utf8)!
p.useExtendedAuthentication = true
p.serverCertificateIssuerCommonName = vpnhost
p.disconnectOnSleep = false
print("Password:")
print(password.data(using: .utf8)!)
var rules = [NEOnDemandRule]()
let rule = NEOnDemandRuleConnect()
rule.interfaceTypeMatch = .any
rules.append(rule)
NEVPNManager.shared().localizedDescription = "My VPN"
NEVPNManager.shared().protocolConfiguration = p
NEVPNManager.shared().onDemandRules = rules
NEVPNManager.shared().isOnDemandEnabled = true
NEVPNManager.shared().isEnabled = true
NEVPNManager.shared().saveToPreferences { error in
guard error == nil else {
print("NEVPNManager.saveToPreferencesWithCompletionHandler failed: \(error!.localizedDescription)")
return
}
VPNManager.sharedManager.startVPNTunnel()
}
}
此外,我无法在应用内自动启动它,因为无法识别VPNManager.sharedManager.startVPNTunnel()
此外,这会出现在日志中:
2017-06-04 13:02:40.143478-0400 VPN[1212:157220] [] (null): SecItemCopyMatching failed: -50
答案 0 :(得分:0)
p.authenticationMethod = .none将其更改为NEVPNIKEAuthenticationMethodSharedSecret,然后它不再需要密码。
谢谢你