How do I automatically reconnect to the VPN when the network status changes?

I use NEVPNManager. I found that when the network status changes, the VPN disconnects. I tried using NEOnDemandRuleConnect to automatically reconnect, but there was a problem with the VPN not being able to disconnect manually. Because every time it disconnects, it automatically reconnects. What can be done about it?

NEOnDemandRuleConnect *connectRule = [[NEOnDemandRuleConnect alloc] init];
connectRule.interfaceTypeMatch = NEOnDemandRuleInterfaceTypeAny;
NEOnDemandRuleIgnore *ignoreRule = [[NEOnDemandRuleIgnore alloc] init];
ignoreRule.interfaceTypeMatch = NEOnDemandRuleInterfaceTypeAny;
[self.vpnManager setOnDemandRules:@[connectRule, ignoreRule]];
[self.vpnManager setOnDemandEnabled:YES];

I also to monitor the change of the connection state. When the connection is disconnected, an attempt is made to reconnect.However, I don't think this is a good solution, because you don't need to open the APP to open the VPN, so when users connect to the VPN through the phone Settings, this reconnection mechanism should not work.

Now I listen for changes in the VPN connection status, and when the VPN disconnects, I actively try to reconnect. However, I don't think this is a good solution, because you don't need to open the APP to open the VPN, so when users connect to the VPN through the phone Settings, this reconnection mechanism should not work.

How do I automatically reconnect to the VPN when the network status changes?
 
 
Q