Ios 安装VPN时不保存密码
我正在尝试在我的应用程序上安装VPN,问题是安装后,IOS会提示我输入VPN密码,即使代码中指定了密码 我的代码有什么问题Ios 安装VPN时不保存密码,ios,swift,swift3,vpn,Ios,Swift,Swift3,Vpn,我正在尝试在我的应用程序上安装VPN,问题是安装后,IOS会提示我输入VPN密码,即使代码中指定了密码 我的代码有什么问题 @IBAction func Install(_ sender: Any) { NEVPNManager.shared().loadFromPreferences { error in // setup the config: let password = "vpnpass" le
@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
p、 authenticationMethod=.none将其更改为NevpnikeAuthenticationMethodsSharedSecret,则不再询问密码 谢谢你的问候