Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring ios8 VPN configuration and control in Swift

Tags:

ios

swift

vpn

I'm trying to set up an in-app VPN connection using ios8's VPN configuration and control but I'm stuck. I'm using the resources at http://ramezanpour.net/post/2014/08/03/configure-and-manage-vpn-connections-programmatically-in-ios-8/ to help, but I'm having problems binding the protocol to the VPN manager.

So far, I have the following code, and as per the tutorial above, you then need to bind the protocol to the manager...

func initVPN() {
    let manager: NEVPNManager = NEVPNManager.sharedManager()
    let p = NEVPNProtocolIPSec()

    p.username = "ospencer"
    p.passwordReference = getPasscodeNSData("vpnPassword")
    p.serverAddress = "vconnect.uk.capgemini.com"
    p.authenticationMethod = NEVPNIKEAuthenticationMethod.SharedSecret
    p.sharedSecretReference = getPasscodeNSData("vpnSharedSecret")
    p.useExtendedAuthentication = true
    p.disconnectOnSleep = false

I've tried writing manager.protocol = p, but I get the error "expected member name following ." and "expected identifier in protocol declaration". I've tried a setProtocol function that is used in some of the Objective C examples '[manager setProtocol:p]', but that doesn't seem to exist in the latest xcode build.

Can anyone help? Also there appears to be almost no details about using the VPN functionality on the internet - even on Apple's site. Any pointers would be useful.

Thanks,

Oliver.

like image 349
Oliver Spencer Avatar asked Oct 21 '22 00:10

Oliver Spencer


1 Answers

To use a reserved word as an identifier, put a backtick (`) before and after it. For example, class is not a valid identifier, but

class is valid. The backticks are not considered part of the identifier; x and x have the same meaning.

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html

like image 182
embinder Avatar answered Oct 22 '22 15:10

embinder