I have vpn info, which I try to configure in my application. when I call startVPNTunnel my vpn connection status changed to: connecting, disconnecting - so I can't establish my vpn connection.
But when i configure my vpn info in settings->general manual configure vpn - it is work fine
I configured my NEVPNProtocol
and try to connected
but it doesn't work
But when i configure my vpn info in settings->general manual configure vpn - it is work fine
I configured my NEVPNProtocol
Code Block static func protocolConfiguration(_ account: VPNAccountInfo) -> NEVPNProtocol { let configuration = NEVPNProtocolIKEv2() configuration.authenticationMethod = .none keychain["vpn_server"] = account.server keychain["vpn_remote_id"] = account.remoteIdentifier keychain["vpn_username"] = account.username keychain["vpn_password"] = account.password configuration.serverAddress = keychain["vpn_server"] configuration.remoteIdentifier = keychain["vpn_remote_id"] configuration.username = keychain["vpn_username"] configuration.passwordReference = keychain[attributes: "vpn_password"]?.persistentRef configuration.useExtendedAuthentication = true configuration.disconnectOnSleep = false return configuration }
and try to connected
Code Block static func connectToVPNAccount(_ account: VPNAccountInfo) { guard !connectionState.value.isInProgress else { return } connectionState.value = .connecting // Legacy? // For no known reason the process of saving/loading the VPN configurations fails. On the 2nd time it works vpnManager.loadFromPreferences(completionHandler: { (error: Error?) in if (error != nil) { disconnectInternal() print("Could not load VPN Configurations") return } vpnManager.protocolConfiguration = protocolConfiguration(account) vpnManager.localizedDescription = "Onion VPN" vpnManager.isEnabled = true vpnManager.saveToPreferences(completionHandler: { (error:Error?) in if (error != nil) { disconnectInternal() print("Could not save VPN Configurations") return } do { try vpnManager.connection.startVPNTunnel() DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: { connectionState.value = .connected }) } catch let error { disconnectInternal() print("Error starting VPN Connection \(error.localizedDescription)") } }) }) }
but it doesn't work