彼ら。
サーバーへの VPN 接続をセットアップしようとしていますが、問題が発生します。
手動で設定してみましたが、うまくいきました。
これが私の構成コードです。サーバーオブジェクトには確かに名前と正しいホストがあり、拡張認証を無効にしようとしました。Afaik のリモート識別子とローカル識別子は単なるランダムな文字列なので、何が間違っていたのかわかりません。
fileprivate func updateCurrentVPN(withServer server: Server, completion: ((Bool) -> Void)?) {
let passwordRef = KeychainWrapper.standard.dataRef(forKey: self.account.username)
let secretRef = KeychainWrapper.standard.dataRef(forKey: API.ipsecSecretKey())
// checking if the strings are correct in a debugger
let password = KeychainWrapper.standard.string(forKey: self.account.username)
let secret = KeychainWrapper.standard.string(forKey: API.ipsecSecretKey())
// VPN
let manager = NEVPNManager.shared()
manager.loadFromPreferences { (error) in
if (error != nil)
{
print("Error: ", error.debugDescription)
completion?(false)
}
else
{
let prtcl = NEVPNProtocolIPSec()
prtcl.username = self.account.username
prtcl.passwordReference = passwordRef
prtcl.serverAddress = server.host
prtcl.authenticationMethod = NEVPNIKEAuthenticationMethod.sharedSecret
prtcl.sharedSecretReference = secretRef
prtcl.localIdentifier = "Test iOS device"
prtcl.remoteIdentifier = server.name
prtcl.useExtendedAuthentication = true
prtcl.disconnectOnSleep = false
manager.isEnabled = true
manager.protocolConfiguration = prtcl
manager.isOnDemandEnabled = false
manager.localizedDescription = "MyVPN Configuration"
manager.saveToPreferences(completionHandler: { (error) in
if (error != nil)
{
print("Error: ", error.debugDescription)
completion?(false)
}
else
{
self.serverButton.setTitle(server.name, for: UIControlState.normal)
print("VPN prefs saved")
completion?(true)
}
})
}
}
構成が保存された後、次のことを行います。
let manager = NEVPNManager.shared()
do {
try manager.connection.startVPNTunnel()
} catch {
print(error.localizedDescription)
connectButton.setTitle("da failure :(", for: UIControlState.normal)
}
しかし、エラーがスローされることはなく、システム アラートで「VPN サーバーとのネゴシエーションが失敗しました」というメッセージが表示されるだけです。ところで、この種のエラーをキャッチすることは可能ですか?