NetworkExtension connectOnDemand rules doesn't work

前端 未结 2 1036
天涯浪人
天涯浪人 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]
    
    0 讨论(0)
  • 2021-01-24 21:52

    You need to add the line

    manager.onDemandEnabled = true
    
    0 讨论(0)
提交回复
热议问题