iOS SDK Documentation

The documentation describes the steps to integrate ActSDK into your iOS project.

App Store Configuration

Configure permissions on App Store.

This document works in 2 sections:

  • providing the App ID permissions,
  • creating the right provisioning profile

Setting App ID
#1

Visit Apple Developer Portal - https://developer.apple.com/account/resourcesand log in with your credentials.

  1. 1. Edit your AppID and enable the following:
    • App Groups
    • Network Extensions
    • Personal VPN
  2. 2. Create a new AppID for the VPN Extension. Give it a name My App VPNExtension and bundle identifier com.mycompany.myapp.vpnExtension (replace com.mycompany.myapp with your App’s bundle id). Enable the following on the newly created AppID.
    • App Groups
    • Network Extensions
    • Personal VPN
  3. 3. Go to Identifier|App Groups. Create a new group and give it a name and a group id. Let’s say the name is group.actsdk
  4. 4. Then go to the AppId of your app, edit it, edit the App Groups and select the newly created group id above.
  5. 5. Then go to the AppId of the vpnExtension, edit it, edit the App Groups and select the newly created group id above.

Creating Provisioning Profile
#2

  1. 1. In your app’s provisioning profile, ensure it has the entitlement for Network Extension iOS.
  2. 2. Create a new provisioning profile for the extension product_code. Ensure it has the entitlement forNetwork Extension iOS.
  3. 3. Download the generated provisioning profile to your machine, we will use them next.

Xcode Setup

Configure Xcode build settings and add files.
#1

Now that we have configured the App Store, we move to configure Xcode, import the right files and setup the right entitlements, build settings and build phases.
Note: Assume extracted folder path - /path/to/ActSDK and hereby refered as the “SDK path”; and bundle id(com.mycompany.myapp), hereby refered as bundleID

Setup:

  1. 1. Extract ActSDK_n.nnn.tar.gz (tar xzvf ActSDK_n.nnn.tar.gz) in a folder. The folder structure looks like
    • SDK/includes: contains header files
    • SDK/Libs: contains compiled library
    • SDK/*.m: contains some extra files needed for compilation
  2. 2. Open your app project in Xcode.
  3. 3. File->New->Target, Under iOS tab, in the Application Extensions section, choose Packet Tunnel Provider Extension.
  4. 4. Give the name ‘vpnExtension’, so the bundle name becomes bundleID.vpnExtension. The name is important as the SDK needs the extension to be this name.
  5. 5. Overwrite the contents of VPNSDKSample/PacketTunnelProvider.h and VPNSDKSample/PacketTunnelProvider.minto the Xcode generated ones.

Editing Build Settings
#2

  1. Go to Build Settings of vpnExtension target, and:
    • under Header Search Paths add SDK path and set the search to recursive.
    • under Framework Search Paths add SDK path and set the search to recursive.
    • under Library Search Paths add SDK path and set the search to recursive.
    • set the Enable Bitcode option to No.
Repeat the changes for the app target’s build settings as well.

Editing Build Settings
#3

  1. Go to Build Phases of vpnExtension target, and:
    • under Compile Sources add
      1. NSData+Gzip.m,
      2. NSURLProtocol+WKWebViewSupport.m and
      3. JSONKit.m to the project (present in the SDK directory). Add the Complier Flag -fno-objc-arc
    • under “Link Binary With Libraries” > ‘+’ sign > “Add Other…”, then navigate to /path/to/ActSDK/Libs and add libactmobilemono.a.
    • underLink Binary With Liraries, click on the + sign. Then in the search box, type and add the following framework libraries.
      • UIKit.framework
      • SystemConfiguration.framework
      • NetworkExtension.framework
      • libresolv.tbd
      • libz.tbd
      • EventKitUI.framework
      • ImageIO.framework
      • libsqlite3.tbd
      • CoreData.framework
Do the above “Build Phases” changes to your app target as well.

Updating Info plist and Capabilities
#4

  1. Ensure value of CFBundleDisplayName in the plist is set to Your App VPN or similar. This will show up in the Apple VPN Profiles.
  2. Import the downloaded provisioning profiles into your Xcode for the respective targets.
  3. Click on Capabilities tab of your app target settings.
    • Turn on Capabilities. Choose Packet Tunnel for its capabilities.
    • Turn on Personal VPN.
    • Turn on App Groups and choose the group id that you created earlier (e.g. group.actsdk).

Initialize the SDK

Configure SDK and get it ready for use.
#1

  • 1. Import “ActSDK.h” header file in your App Delegate.
  • 2. Call the code with the assigned token. This should return true and SDK will be ready to use as the app is launched.
                          [ActSDK initWithToken:NSString forVPN:BOOL];
                        
  • 3. When the above function returns true, call the following code:
    [ActSDK startProxy];
    [ActSDK setOnDemandAllowed:BOOL]; 
                            // enables the on-Demand feature, default is false - set it to false when not intending to do so.
    [ActSDK setVPNServerName:@"vpn.sdk.sample"];
    [ActSDK initVpnWithOnDemand:BOOL withCompletion:]; 
                            // default bool value is false
                          
  • 4. Inside the completion handler, if there is no error - the delegate for ActSDK can be set.
    [ActSDK setDelegate:UIViewController];

Overriding the code
#2

If you want to override/have your own PacketTunnelProvider.m-

  • Make the new .h/.m file pair, say NewPacketTunnelProvider.m which is also the class name.
  • Inherit from ActPacketTunnelProvider.
  • Under NSExtension section, the class defined for NSExtensionPrincipalClass (which also needs to be .m file) needs to be changed to NewPacketTunnelProvider.

VPN

Use the VPN feature effectively.
#1

  1. 1. To fetch the list of region hostnames and region labels:
    [ActSDK getRegionsIncludingAliases:YES]; 
                             // region hostnames - dns name
                          
    [ActSDK getRegionLabelsIncludingAliases:YES]; 
                            // region labels - human friendly location names
                          
  2. 2. To set the current region, call the following code with the region hostname:
    [ActSDK changeRegion:NSString]; 
                            // // region hostname
    [[NSUserDefaults standardUserDefaults] setValue:NSString forKey:@"selected_accel_label"]; 
                            // region label name
                          
  3. 3. -(void)ActRegionsUpdated;will be triggered when regions are available or updated from the SDK. Refer to ActSDKDelegatefor delegate supplied functions.
  4. 4. For toggling VPN:
                            [ActSDK connectVPNwithCompletion:];
                          
                            [ActSDK disconnectVPNwithCompletion:];
                          
  5. To get the VPN status and change for notification:
                            [ActSDK getVPNStatus];
                            // returns current NEVPNStatus
                          
                            [ActSDK registerForVpnStatusChange:id withMethodSelector:SELECTOR];
                            // register a listener for when VPN status changes
                          

WebProxy

Setup and use web proxy - fast and easy.
#1

  1. Import ActSDK.h, ActProxyURLProtocol.h and NSURLProtocol+WKWebViewSupport.h header files.
    #import "ActSDK.h"
                                #import "ActProxyURLProtocol.h"
                                #import "NSURLProtocol+WKWebViewSupport.h"
  2. Register your app for “http” and “https” scheme via following code. This will help iOS system present your app as a browser.
                            [NSURLProtocol wk_registerScheme:@"http"];
                            [NSURLProtocol wk_registerScheme:@"https"];
                          
  3. Proxy can be toggled by calling register/unregister ActProxyURLProtocol class.
                            [NSURLProtocol registerClass:[ActProxyURLProtocol class]];
                            // turns the proxy on
                          
                            [NSURLProtocol unregisterClass:[ActProxyURLProtocol class]];
                            // turns the proxy off