- install via CocoaPods
- Don't you have any VPN Server ? , you can look here : https://www.digitalocean.com/community/tutorials/how-to-set-up-an-ikev2-vpn-server-with-strongswan-on-ubuntu-18-04-2
platform :ios, '11.0'
# You need to set target when you use CocoaPods 1.0.0 or later.
target 'SampleTarget' do
use_frameworks!
pod 'BetterVPNManager'
end
//Import Framework
import BetterVPNManager
//Create your VPN Manager variable
let vpn = VPNManager.shared
vpn.delegate = self
//Create your VPN Account and configurations
let vpnAccount = VPNAccount(type: VPNProtocolType.IKEv2, title: "TITLE SEEN IN SETTINGS", server: "IP HERE", account: "bd2147240ab2471d", groupName: "Group Name Of Your VPN", remoteId: "Remote IP Address(Same most of the time)", alwaysOn: true)
//Set your account password and secret
vpnAccount.passwordRef = "YourVPNPassword".data(using: .utf8)
//If you are using IPSec you can use this in order to set secret
vpnAccount.secretRef = "YourVPNSecret".data(using: .utf8)
//Note : If you want to secure you secrets and passwords for your VPN you can use some Keychain wrapper
//Save and connect your
vpn.saveAndConnect(account : vpnAccount)
//Only Save account then connect
vpn.save(account : vpnAccount)
vpn.connect()
//Disconnect
vpn.disconnect()
//Remove saved Account
vpn.removeProfile()
//Config On Demand (Connect only on request is made)
vpn.configOnDemand()
VPNManagerDelegate Methods:
public func VpnManagerConnectionFailed(error : VPNCollectionErrorType , localizedDescription : String)
This called when connection failed with error type and description
public func VpnManagerConnected()
This method called when connection established successfully
public func VpnManagerDisconnected()
This method called when disconnect action made successfully
public func VpnManagerProfileSaved()
This method called when you save your VPN account
public func VpnManagerProfileDeleted()
This method called when you delete your VPN account
- Swift 5
- iOS 11.0 or above.