iOS VPN Connection Blocks Switching 4G to WiFi Connection

Viewed 1357

I am creating a VPN connection in Swift with the on demand connect rule below:

        let config = NEVPNProtocolIPSec()
        config.serverAddress = ""
        config.username = ""
        config.passwordReference = ""
        config.authenticationMethod = .sharedSecret
        config.sharedSecretReference = ""
        config.useExtendedAuthentication = true
        config.disconnectOnSleep = true

        let connectRule = NEOnDemandRuleConnect()
        connectRule.interfaceTypeMatch = .any
        vpnManager.onDemandRules = [connectRule]

        vpnManager.protocolConfiguration = config
        vpnManager.localizedDescription = ""
        vpnManager.isOnDemandEnabled = true
        vpnManager.isEnabled = true

This connection works fine. If I am using WiFi it reconnects after disconnecting from WiFi but not vice versa. If am using cellular connection and try to activate WiFi, the phone does not connect to WiFi until I disconnect it from the VPN manually. I believe an active VPN connection blocks switching from 4G to WiFi.

How can I resolve this issue?

1 Answers
Related