Unified VPN SDK demo for Apple
This is a demo application for Apple with basic usage of Unified VPN SDK.
Prerequisites
The following prerequisites are required to use the SDK:
iOS 18 or newer
Latest version of Xcode (recommended)
Setup
Clone app source code locally from GitHub.
Open Xcode and create iOS application with additional Network Extension target:
Application target
Network Extension target
Configure both the Application and Network Extension targets:
Add following system frameworks to your project dependencies:
NetworkExtension
Security
libz.tbd
In your project: Project > Build Settings:
Set Enable Bitcode to "NO"
Set Other Linker Flags to
-ObjC
Enable Network Extension and Personal VPN entitlements for both application and network extension targets
Create App Group that will be used on both targets
Install the Unified SDK:
Add VPNApplicationSDK.framework for Application target
Add VPNTunnelProviderSDK.framework for Network Extension target
Configure the Network Extension:
Make your PacketTunnelProvider class from Network Extension target extend AFPacketTunnelProvider:
// PacketTunnelProvider.swift import VPNTunnelProviderSDK class PacketTunnelProvider: AFPacketTunnelProvider {}
Build the project.
Usage
Sign in at pango-cloud.com.
{% hint style="info" %} Note that at this time, it is not possible for users to create their own accounts directly if they do not already have an account established with example.com. Please contact your sales representative to initiate account creation as part of the project and client onboarding process or contact us. We apologize for any inconvenience. {% endhint %}2. In Pango dashboard, create a project and use a name for your project as a Public key. Private key is optional.
Navigate to the
Network
tab from the navigation bar. Then, click on theAdd location
button.In Pango dashboard, navigate to the dashboard and locate your
carrier_id
.You can find the backend URL for Prod/Stage/Dev here.
You are almost ready to connect to the VPN. To initiate the VPN connection process in the demo app:
In your AppDelegate or other shared Singleton object, initialize Unified SDK:
// AppDelegate.swift or your own Hydra holding singleton import VPNApplicationSDK // ... lazy var vpnClient : AFHydra = { AFHydra.withConfig(AFConfig.init(block: { (builder) in builder.baseUrl = "BASE_URL"; builder.carrierId = "CARRIER_ID"; builder.groupId = "group.YOUR.GROUP.NAME"; builder.networkExtensionBundleId = "com.yourcompany.AWESOME_APP.neprovider"; })) }()
Replace placeholders with your values obtained from developer portal and your XCode or Apple Developer Portal configuration.
Perform login:
vpnClient.login(AFAuthMethod.anonymous(), completion: { [unowned self] (e, user) in // Process result })
Start VPN connection:
vpnClient.startVpn({ (country, error) in // VPN is being started to server in country `country` // Rely on notification center status notifications for exact VPN state })
Handle VPN state notifications:
vpnClient.notificationCenter.addObserver(forName: NSNotification.Name.AFVPNStatusDidChange, object: nil, queue: nil) { [unowned self] (notification) in // Process VPN status changes here if vpnClient.vpnStatus() == .connected { // Do stuff } }
Your device is now connected to the VPN. To verify the connection:
Open any browser on your device.
Navigate to whatsmyip.com (or any other site which can identify your IP).
Observe that the IP address displayed is different from your device's actual IP address, confirming that traffic is being routed through the VPN.
To terminate the VPN connection when finished, call the appropriate disconnect method in the SDK.
Features usage
Server country selection
If you have to choose VPN server country before connecting, you can call availableCountries
and then startVpn
with specific country:
// Get a list of countries
vpnClient.availableCountries { [weak self] (e, countries) in
// Do stuff
self.someCountry = countries[0]
}
// Start VPN with different country
vpnClient.startVpn(with: self.someCountry, completion: { (country, e) in
})
Documentation
For more detailed information, please refer to Unified VPN SDK for Apple.
Last updated
Was this helpful?