I'm working on iOS application, which establishes a VPN connection.
I have following code:
let connectRule = NEOnDemandRuleConnect()
connectRule.interfaceTypeMatch = .any
connectRule.probeURL = URL(string: "https://www.google. com")
What I do:
- Added VPN profile to iPhone's settings
- Successfully connected to VPN
- iPhone goes to sleep
- Disable my VPN server
After this step, VPN connection is going to this loop:
- VPN server is disabled, so VPN connection goes off
- But network on iPhone is reachable (cellular of wifi) and probeUrl is reachable, so VPN tries to connect
- VPN connection fails to connect (because of VPN server is disabled) and we are going to step 1
How to solve this loop? I guess, the right scenario should be : system does not try to connect to VPN if VPN server is unreachable.