NetworkExtension connectOnDemand rules doesn't work

前端 未结 2 1055
天涯浪人
天涯浪人 2021-01-24 21:08

I have an app with VPN config created by the new NetworkExtension framework. It works just fine, but now I need to add some rules to turn this VPN only when I\'m trying to conne

2条回答
  •  渐次进展
    2021-01-24 21:37

    I made it work with the next rules:

    let onDemandRule = NEOnDemandRuleEvaluateConnection()
    let evaluateRule = NEEvaluateConnectionRule(matchDomains: ["*.some-site.com"], andAction: .ConnectIfNeeded)
    evaluateRule.probeURL = NSURL(string: "https://a.url.accecable.only.from.vpn")
    
    onDemandRule.connectionRules = [evaluateRule]
    manager.protocolConfiguration = config
    manager.onDemandRules = [onDemandRule]
    

提交回复
热议问题