網絡擴展連接需求規則不起作用。

[英]NetworkExtension connectOnDemand rules doesn't work


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 connect to a specific URL. I planed to use NEVPNManager's connectOnDemand feature, but it does`t seem to be working for me. When I'm opening http://some-site.com in safari my VPN connection should establish, but for some reason it does't. I tried a different type of configurations as well as using generated .mobileconfig files to make connectOnDemand work, but with no luck. Whats wrong with it? I'm testing on code like this:

我有一個由新的NetworkExtension框架創建的VPN配置的應用程序。它運行良好,但是現在我需要添加一些規則,當我嘗試連接到一個特定的URL時,才會打開這個VPN。我計划使用NEVPNManager的connectOnDemand特性,但它似乎並不適合我。當我在safari中打開http://somesite.com時,我的VPN連接應該建立,但出於某種原因,它沒有。我嘗試了不同類型的配置,以及使用生成的.mobileconfig文件,以使連接需求工作,但是沒有運氣。什么錯了嗎?我正在測試這樣的代碼:

let manager = NEVPNManager.sharedManager()

manager.enabled = true

manager.loadFromPreferencesWithCompletionHandler { (err) -> Void in
    manager.removeFromPreferencesWithCompletionHandler { (err0) -> Void in
                print("err0 \(err0)")
                print("err \(err)")
                let config = NEVPNProtocolIPSec()
                config.localIdentifier = "NEVPNProtocolIPSec"
                config.remoteIdentifier = "NEVPNProtocolIPSecRemote"
                config.disconnectOnSleep = true
                config.serverAddress = server
                config.authenticationMethod = .Certificate
                //configurating here
                manager.protocolConfiguration = config
                let onDemandRule1 = NEOnDemandRuleConnect()
                onDemandRule1.DNSSearchDomainMatch = ["some-site.com", "*.some-site.com"]

                manager.onDemandRules = [onDemandRule1]
                manager.onDemandEnabled = true
                manager.saveToPreferencesWithCompletionHandler({ (err2) -> Void in
                    print("err2 \(err2)")
                })
            }
        }

2 个解决方案

#1


6  

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]

#2


0  

You need to add the line

你需要添加一行。

manager.onDemandEnabled = true

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/04/07/72a050748e3e4c095b3c9c7d08eadb8d.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com