我想创建一个可行的样本但直到现在才取得成功.因此,我创建了具有DNS代理权利的网络扩展,并添加了DNS代理提供程序.这是代码:
class DnsproxyProvIDer: NEDnsproxyProvIDer { let defaults = UserDefaults(suitename: "group.com.securly.dnsproxy") overrIDe init() { NSLog("QNEDnsproxy.ProvIDer: init") super.init() // +++ might want to set up KVO on `systemDNSSettings` } overrIDe func startProxy(options:[String: Any]? = nil,completionHandler: @escaPing (Error?) -> VoID) { NSLog("QNEDnsproxy.ProvIDer: start") // self.defaults?.set("DIDStart",forKey: "DIDStart") completionHandler(nil) } overrIDe func stopProxy(with reason: NEProvIDerStopReason,completionHandler: @escaPing () -> VoID) { NSLog("QNEDnsproxy.ProvIDer: stop") completionHandler() } overrIDe func handleNewFlow(_ flow: NEAppProxyFlow) -> Bool { NSLog("QNEDnsproxy.ProvIDer: new flow (denIEd)") // self.defaults?.set("DIDHandleNewFlow",forKey: "DIDHandleNewFlow") return true }}
然后在AppDelegate中,我声明一个NEDnsproxyManager并将其用作:
class AppDelegate: UIResponder,UIApplicationDelegate { var window: UIWindow? let manager = NEDnsproxyManager.shared() func application(_ application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { self.enable() return true } private func enable() { self.update { self.manager.localizedDescription = "DnsproxySample" let proto = NEDnsproxyProvIDerProtocol() // proto.provIDerConfiguration = +++ proto.provIDerBundleIDentifIEr = "com.securly.dnsproxy" self.manager.provIDerProtocol = proto self.manager.isEnabled = true } } private func disable() { self.update { self.manager.isEnabled = false } } private func update(_ body: @escaPing () -> VoID) { self.manager.loadFromPreferences { (error) in guard error == nil else { NSLog("DnsproxySample.App: load error") return } body() self.manager.savetoPreferences { (error) in guard error == nil else { NSLog("DnsproxySample.App: save error") return } NSLog("DnsproxySample.App: saved") } } }}
疑问/问题:
>为什么不调用startProxy或handleNewFlow?设置有什么问题吗?
>我如何提及自定义DNS地址?
>应用目标上的权利
> Dnsproxy扩展的权利
红线类似于:group.com.xzy.project_name
> Extension上的Info.p@R_502_6818@文件
> AppDelegate
@R_502_5565@ UIKit@R_502_5565@ NetworkExtension@UIApplicationMainclass AppDelegate: UIResponder,dIDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { self.enable() return true } private func enable() { self.update { self.manager.localizedDescription = "DNS" let proto = NEDnsproxyProvIDerProtocol() proto.provIDerBundleIDentifIEr = "EXTENSION_BUNDLE_IDENTIFIER_WHICH_HAS_DNS_PROXY" self.manager.provIDerProtocol = proto self.manager.isEnabled = true } } private func disable() { self.update { self.manager.isEnabled = false } } private func update(_ body: @escaPing () -> VoID) { self.manager.loadFromPreferences { (error) in guard error == nil else { NSLog("DNS Test App: load error") return } body() self.manager.savetoPreferences { (error) in guard error == nil else { NSLog("DNS Test App: save error") return } NSLog("DNS Test App: saved") } } }}
请勿忘记在此处更改BUNDLE IDENTIFIER proto.provIDerBundleIDentifIEr =“EXTENSION_BUNDLE_IDENTIFIER_WHICH_HAS_DNS_PROXY”
> DnsproxyProvIDer
@R_502_5565@ NetworkExtensionclass DnsproxyProvIDer: NEDnsproxyProvIDer { overrIDe init() { NSLog("DnsproxyProvIDer: init") super.init() } overrIDe func startProxy(options:[String: Any]? = nil,completionHandler: @escaPing (Error?) -> VoID) { NSLog("DnsproxyProvIDer: startProxy") completionHandler(nil) } overrIDe func stopProxy(with reason: NEProvIDerStopReason,completionHandler: @escaPing () -> VoID) { NSLog("DnsproxyProvIDer: stopProxy") completionHandler() } overrIDe func sleep(completionHandler: @escaPing () -> VoID) { NSLog("DnsproxyProvIDer: sleep") completionHandler() } overrIDe func wake() { NSLog("DnsproxyProvIDer: wake") } overrIDe func handleNewFlow(_ flow: NEAppProxyFlow) -> Bool { NSLog("DnsproxyProvIDer: handleFlow") return false }}
>作为最后一步,在真正的iOS设备上运行应用程序.>如果要显示扩展日志,请从Mac打开Console.app.>要调试扩展名:应从运行菜单中选择主应用程序.从Xcode的DeBUG菜单中选择Attach to Process by PID或name …然后输入扩展名,按Attach按钮.在XYZ的iPhone上看到等待附加到EXTENSION_name后.在iOS设备上运行您的应用目标.
总结以上是内存溢出为你收集整理的如何在iOS 11中使用NEDNSProxyProvider全部内容,希望文章能够帮你解决如何在iOS 11中使用NEDNSProxyProvider所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)