Our VPN was implemented using the NEPacketTunnelProvider, in the case of back end permanent errors (e.g. permission denied), we would stop the VPN tunnel by calling the cancelTunnelVPNWithError method. This did stop the VPN, however the VPN would auto reconnect and enter an infinite loop of connecting and disconnecting due to the back end permanent error.
The VPN was turned on from the VPN settings. To completely disable the VPN, we need to either delete the VPN configuration, or manually tap on the toggle to disable.
Sample code:
- (void)PPNService:(PPNService *)PPNService didStopWithError:(nullable NSError *)error {
SUBSPPNStatusData *ppnStatusData = [[SUBSPPNStatusData alloc] init];
SUBSPPNToggleStatus *toggleStatus = [[SUBSPPNToggleStatus alloc] init];
toggleStatus.ppnToggleStatus = SUBSPPNToggleStatus_PPNToggleStatus_Off;
if (error) {
[_ppnSessionManager logSessionEnd];
[self cancelTunnelWithError:error];
ppnStatusData.ppnStatus = SUBSPPNStatusData_PPNStatus_StoppedWithError;
PPNStatusDetails *details = error.userInfo[PPNStatusDetailsKey];
}
Question: Why does the VPN auto reconnect after calling the cancel method? Any solutions to completely stop the VPN on permanent errors.