gpt4 book ai didi

ios - NetworkExtension connectOnDemand 规则不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 05:57:20 29 4
gpt4 key购买 nike

我有一个应用程序,其 VPN 配置由新的 NetworkExtension 框架创建。它工作得很好,但现在我需要添加一些规则来仅在我尝试连接到特定 URL 时才打开此 VPN。我计划使用 NEVPNManager 的 connectOnDemand 功能,但它似乎对我不起作用。当我打开 http://some-site.com在 safari 中我的 VPN 连接应该建立,但由于某种原因它没有。我尝试了不同类型的配置以及使用生成的 .mobileconfig 文件来使 connectOnDemand 工作,但没有成功。它出什么问题了?我正在测试这样的代码:

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)")
})
}
}

最佳答案

我让它与下一个规则一起工作:

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]

关于ios - NetworkExtension connectOnDemand 规则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36478376/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com