I am creating a app that will be filter all network traffics from Iphone or Ipad. I looked into info.plist
but I don't know what setting I have to choice. My expected something like this.
This is my code:
import Foundation
import NetworkExtension
@objc(TestingProxy)
class TestingProxy: NSObject {
let vpnManager = NEVPNManager.shared();
private var vpnLoadHandler: (Error?) -> Void {
return { (error:Error?) in
if ((error) != nil) {
print("Could not load VPN Configurations")
return;
}
let p = NEVPNProtocolIPSec()
p.username = "SOME_USERNAME"
p.serverAddress = "example.com"
p.authenticationMethod = NEVPNIKEAuthenticationMethod.sharedSecret
let kcs = KeychainService();
kcs.save(key: "SHARED", value: "MY_SHARED_KEY")
kcs.save(key: "VPN_PASSWORD", value: "MY_PASSWORD")
p.sharedSecretReference = kcs.load(key: "SHARED")
p.passwordReference = kcs.load(key: "VPN_PASSWORD")
p.useExtendedAuthentication = true
p.disconnectOnSleep = false
self.vpnManager.protocolConfiguration = p
self.vpnManager.localizedDescription = "Contensi"
self.vpnManager.isEnabled = true
self.vpnManager.saveToPreferences(completionHandler: self.vpnSaveHandler)
}
}
private var vpnSaveHandler: (Error?) -> Void {
return { (error:Error?) in
if (error != nil) {
print("Could not save VPN Configurations")
return
} else {
do {
try self.vpnManager.connection.startVPNTunnel()
} catch let error {
print("Error starting VPN Connection \(error.localizedDescription)");
}
}
}
}
}
Any help?
I think I found the answer. Something like this, but I don't have Development account so I could not confirm that for now.
Go to Xcode -> Project -> Targets -> Capabilities and Enable VPN and Enable Network
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.