Hello, I am developing a vpn app using several protocols, one of them is Wireguard.
When the app is terminated, there is a tunnel that vpn is still communicating with which is a subclass of NEPacketTunnelProvider.
In some cases when stopping the tunnel using wireguardAdapter.stop(withcompletionHandler:) func it may throws an error of stopping the tunnel, in this case I want to force stop the tunnel, but when on-demand is on it will try to reconnect and the user will remains without internet connection on his wifi until he turns off the on-demand by his hand.
I tried to call the NEVPNMnager and load preference and then turn on-demand of then stop the tunnel and it did not works.
here is my code.
`
let manager = NEVPNManager.shared()
manager.loadFromPreferences { error in
if let error = error {
self.wgLogger.log("Error loading from preferences: \(error, privacy: .public)")
return
}
manager.isOnDemandEnabled = false
manager.saveToPreferences { error in
if let error = error {
self.wgLogger.log("Error saving to preferences: \(error, privacy: .public)")
return
}
manager.connection.stopVPNTunnel()
self.wgLogger.log("VPN tunnel stopped successfully.")
}
}
13
0
1.4k