OpenVPNAdapter
OpenVPNAdapter copied to clipboard
Switching from Cellular to WiFi the adapter still uses cellular data and hide the wifi signal icon
I have a requirement to connect vpn only in wifi network. For this I use reachability when wifi is available, I call startVPNTunnel method (vpnManager.connection.startVPNTunnel()) and show wifi signal with vpn (⏚vpn) in device. When wifi not available my logic calls (vpnManager.connection.stopVPNTunnel()) to stop vpn and device shows LTE only, this works fine.
But when I switch on WiFi(also cellular data remains on) again in device my logic calls automatically startVPNTunnel method but vpn is trying connect with cellular data. At this point my logic disconnect it as reachability again shows connected with WAN. If I remove stopVPNtunnel method then vpn connect with LTE and also WiFi is connected in device. After few second all the signal in status bar goes hidden related to signals(⏚,LTE,vpn) but data network is available in device.
I think Vpn adapter always remain connected with LTE even stopVPNTunnel(contains vpnAdapter.disconnect) method called. I am also not able to call any method of PacketTunnelProvider extension in my project's HomeViewController.(to set the adapter's reconnect time interval or to forcefully disconnect vpn adapter)
Tried many things delayed time intervals to startVPNTunnel when wifi again available.But in vein.
Please help me @ss-abramchuk @djubreel
The issue still exists. It happens because a reachability callback is never called when the device connects to the Wi-Fi network.
Here's the code I'm talking about:
override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
...
vpnReachability.startTracking { [weak self] status in
// this code will be never called when device connects to WIfi
guard status == .reachableViaWiFi else { return }
self?.vpnAdapter.reconnect(interval: 5)
}
...
}
If we replace Reachability with NWPathMonitor, this issue could be fixed.