Single Protocol SDK
Last updated
Was this helpful?
Last updated
Was this helpful?
The Single Protocol SDK is the ideal choice when you plan to implement a specific protocol within your application. This SDK is suitable if you intend to utilize a single protocol throughout your app or if you prefer to handle protocol switching manually within your application's codebase.
To view a complete list of of the available APIs, see .
Integrating a VPN SDK into your application typically involves a two-step process: setting up the application target and configuring the network extension target. This process is consistent across most VPN SDKs, with one notable exception - IPSecSDK
.
The first step in the integration process is to configure your application target. This involves modifying your app's build settings, linking necessary libraries, and ensuring that your app has the required permissions and entitlements to utilize the VPN functionality.
The second step is to set up a network extension target. A network extension is a separate process that runs alongside your main application and handles the VPN connection. This step involves creating a new target in your Xcode project, configuring its build settings, and implementing the necessary code to establish and manage the VPN connection.
It's worth noting that IPSecSDK
is an exception to the typical two-step integration process. IPSecSDK
utilizes Apple's internal tunnel implementation, which eliminates the need for you to set up a separate network extension target.
With IPSecSDK
, you only need to focus on setting up the application target. The SDK handles the VPN connection internally, simplifying the integration process.
To get started with the single protocol SDK, use the configuration below as a starting point. This minimal setup provides the easiest way to initialize the SDK and begin using its features.
To connect VPN use function start(location:completion:)
on SDK instance. When VPN is started or an error occurred, completion handler will be called. To obtain VPN connection status you need to subscribe to vpnStateDidChange
notification provided by SDK. For example:
When you receive notification, get updated VPN status from SDK instance state
property and handle this status as designed by your app.
While using Hydra you can also switch location using applyLocationIfConnected(:completion:)
when VPN is in connected status. It will update location in the same network extension (without killing it and starting new one). This method will return error if VPN is not currently connected.
iOS and macOS, both provide an ability to connect to VPN automatically when certain (preconfigured) coditions are met. This functionality is called On Demand.
VPN SDK can be configured for On Demand mode with corresponding configuration via isOnDemandEnabled
and onDemandRules
properties. The SDK could be initialized with this parameter.
If your service provides limited traffic or a transport error occurs (e.g. credentials to VPN nodes are expired), current session will be killed with VPNTunnelError.trafficExceeded
error. If On Demand mode conditions are met, the System will try to restart Network Extension process, until it is up and running. Due to NetworkExtension framework's limitation, it is not possible to disable On Demand mode from Custom Tunnel Provider extension upon receiving these errors. This makes System trying endlessly reconnect to VPN, while Network Extension is unable to provide VPN service due to the error.
In order to overcome this issue, VPN SDK disables real tunneling, leaving Network Extension running in Bypass mode. By doing this, iOS can meet On Demand mode conditions while the traffic is routed locally, without VPN server. It means that user will have their real IP address and there will be no traffic protection.
Whenever app starts, it's highly recommended to check if VPN is connected and if user is out of traffic limit. In this case, it's necessary to disconnect current VPN session and optionally show user a message. To check if current VPN connection is running in Bypass mode read isBypassEnabled
property from SDK instance.
In order to catch situation when user is out of traffic without main app running, use BaseNetworkExtensionDelegate
callback method vpnDidReceiveError(_:)
.
Most of the SDK instance calls are accepting completion blocks with errors. If some error occurs, you will receive non-nil Error
object with an explanation. Some errors types that can be thrown by VPN SDK methods: PartnerAPI.APIError
, VPNSDKError
, VPNTransportError
, VPNTunnelError
. If you need localized description make these types conform to LocalizedError
protocol and provide var errorDescription: String?
property. Then you can use localizedDescription
property on returned Error
.
If you are just disconnected from VPN session, you could also check lastTunnelError
property of SDK instance, if there was an error during network extension initialization or session management system disconnected VPN remotely, there will be VPNTunnelError
case here. You can handle such errors and report if appropriate. Pay attention that this property is always nil
for IPSecSDK
, because we don't have access to internal IPSec implementation.
Some project might consider crash reporting integration (such as, ) for Network Extension side. If your crash reporting framework supports Application Extensions and requires additional code to setup it, put the configuration code inside BaseNetworkExtensionDelegate
's -init
override: