VPN Unlimited SDK for iOS/macOS is shipped as a static framework. It is written in Objective-C and C++ and is available for iOS 13 and OS X 10.15 and later.
Drag and drop VPNUnlimitedSDK.framework into your project.
After the setup is complete, you should be able to use all classes from the SDK by including it with #import <VPNUnlimitedSDK/VPNUnlimitedSDK.h> directive.
The current version of VPN Unlimited SDK uses the following libraries under the hood:
If your project uses one of these libraries and you get conflicts, please contact VPN Unlimited team for further investigation.
You must set Incoming Connections (Server), Outgoing Connections (Client) checkboxes when using Apple's App Sandbox mode.
The current version of VPN Unlimited SDK supports the following VPN protocols:
This SDK is designed in classical OOP style. We provide a handful of classes which you can use in any desired combination. All network calls are synchronous.
Here is the full list of classes:
macOS additional headers:
You can see the complete documentation for each class on the Reference page. Here we just briefly describe the standard workflow.
Currently Bitcode for iOS is not supported.
Use the following method to initialize VPN Unlimited SDK:
[KSVPNUFacade.defaultFacade initializeSettingsWithAppID:<#Application id#> appSecret:<#Application secret#> applicationGroupIdentifier:<#Application group identifier#> appVersion:<#Application version#> sharedKeychainGroupID:<#Shared keychain group#> providerBundleIdentifier:<#Provider bundle identifier#> wgProviderBundleIdentifier:nil profileName:<#VPN profile name#> completion:<#Completion block#>];
In case after the initialization you get the 501 error for each request, check the AppId and AppSecret.
To initialize and set up Standalone macOS SDK, please contact VPN Unlimited team.
As stated previously, all network calls in this SDK are performed synchronously. This means that you should perform them all in a non-main thread, otherwise they will be blocked and never come back. Each method which falls into this category is explicitly documented.
In order to achieve asynchronous behavior, you can use any multithreading technique you prefer. We recommend Grand Central Dispatch. When the operation is finished you can move back to the main thread. You can stay on the secondary thread and perform more networking actions serially, if you like.
KSVPNUFacade is a class which serves as a 'facade' to other VPN Unlimited SDK classes. It hides the complexity of VPN Unlimited SDK by encapsulating most of the needed features.
If you do not want to construct API requests and the VPN configurator by yourself you can use KSVPNUFacade singleton. Please check the documentation for this class, it is suitable for most applications.
Use the following method to register a new user:
registerWithLogin:password:marketingEmails:partnerId:completion
The email address should be a valid one, not generated by a temporary email service.
The password should match the below requirements:
In case of a successful registration, the user will be automatically logged in the system.
BOOL doNotReceiveMarketingEmails = YES; [KSVPNUFacade.defaultFacade registerWithLogin:email password:password marketingEmails:doNotRecieveMarketingEmails partnerId:nil completion:^(NSError *error) {}];
Use the following method to log in:
[KSVPNUFacade.defaultFacade authorizeWithLogin:login password:password completion:completion];
To log out a user, use the method signOutWithCompletion:
The following properties of the object will be cleared: KSVPNUFacade.defaultFacade - currentUserInfo, currentDeviceInfo, currentAccountStatus, currentServersList
[KSVPNUFacade.defaultFacade signOutWithCompletion:^(BOOL successful, NSError *error) {}];
How to retrieve account status of a logged in user?
(void)accountStatusWithCompletion:(void(^)(VPNUAccountStatus *accountStatus, NSError *error))completion;
We recommend to request the account status at the start of the application, after the successful connection, or when disconnecting from a VPN server. The account status includes the following important parameters:
Use the below method to get the full list of VPN servers:
(void)serverListWithOptions:(KSVPNUServerListOptions)mask completion:(void(^)(NSArray<VPNUServerItem *> *serversList, NSError *error))completion
Description of options:
As a result of the command execution, you get an array of VPNUServerItem objects.
To connect to a VPN server, you need to select a server and a connection protocol.
[KSVPNUFacade.defaultFacade startVPNTunnelWithServerItem:selectedServer protocol:protocol completion:completion];
If you want to reconnect or change protocol, you need to stop the VPN connection first:
[KSVPNUFacade.defaultFacade stopVPNWithCompletion:^(NSError *error) {}];
After the VPN connection is stopped, establish the connection again, using the required parameters.
Note:Before establishing the connection, it is recommended to check if the user has a subscription. You can find this information in the userâs account status. In case there is no active subscription, the user will lose access to the internet after the connection, HTTPS websites will not open, and HTTP websites will redirect the user to our website with the offer to get a subscription.
Subscribe for the notification VPNUConnectionStatusDidChangeNotification and check the status of VPN connection by the property:
VPNUConnectionStatus connectionStatus = KSVPNUFacade.defaultFacade.connection.status;
After a successful purchase, you need to call the method of purchase validation on our server.
In the countryCode parameter you need to pass nil
(void)validatePurchaseWithCountryCode:(NSString *)countryCode completion:(void(^)(NSError *error))completion;
After the purchase validation, you need to check the account status. The expiry date of the subscription should be updated - expiredDate.
A temporary account is required to use the VPN service without registration.
To generate and register a temporary account, use the following method
(void)registerFakeAccountWithCompanyDomain:(NSString *)companyDomain partnerId:(NSString *)partnerId completion:(void(^)(NSString *login, NSString *password, NSError *error))completion;
It will return the login/password pair, which should be saved in a secure storage (for example, Keychain). The credentials can be used for a login in the future.
All purchases made with a temporary account are tied to this account. If a user registers a permanent account by themselves, all information and purchases from the temporary account can be transferred to the permanent one. To do this, you need to call the below method:
(void)mergeLogin:(NSString *)login withFakeLogin:(NSString *)fakeLogin fakePassword:(NSString *)fakePassword password:(NSString *)password marketingEmails:(BOOL)doNotReceiveMarketingEmails completion:(void(^)(NSError * error))completion;
Note:After the merge, it is not possible to log in to the temporary account, as it is deleted.
To synchronize a temporary account between iOS devices, iCloud is used. iCloud Drive must be enabled in the device settings.
Saving account:
(void)saveAccountInCloudLogin:(NSString *)login password:(NSString *)password;
Getting an account from iCloud:
(NSDictionary *)loadAccountFromCloud;
To use OpenVPN/KeepSolid Wise protocols, you need to add the Network Extension to the project:
In the XCode select Project file -> Add new target (+) -> Network Extension Provider Type - Packet Tunnel Embedded in application - choose your application target
In the header file, make sure the class your created from VPNUPacketTunnelProvider is inherited.
#import@interface PacketTunnelProvider : VPNUPacketTunnelProvider @end
All predefined methods in the .m file should be deleted.