我正在使用下面的按需连接规则,在Swift中创建VPN连接:
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
这个连接没问题。如果我使用WiFi,它会在断开WiFi后重新连接,但反之不然。如果我正在使用蜂窝连接并尝试激活WiFi,则手机无法连接到WiFi,直到我手动从VPN断开连接。我认为,活跃的VPN连接会阻止从4G切换到WiFi。
我该如何解决这个问题?