How to disable vpn connection loop?

Hello.
I'm working on iOS application, which establishes a VPN connection.

I have following code:
Code Block
let connectRule = NEOnDemandRuleConnect()
connectRule.interfaceTypeMatch = .any
connectRule.probeURL = URL(string: "https://www.google. com")


What I do:
  1. Added VPN profile to iPhone's settings

  2. Successfully connected to VPN

  3. iPhone goes to sleep

  4. Disable my VPN server

After this step, VPN connection is going to this loop:
  1. VPN server is disabled, so VPN connection goes off

  2. But network on iPhone is reachable (cellular of wifi) and probeUrl is reachable, so VPN tries to connect

  3. 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.
How to disable vpn connection loop?
 
 
Q