Before using this class you must authorize or register with the help of VPNUAuthorizer class. You must pass the same VPNUTransport instance to its constructor as you have passed to VPNUAuthorizer instance constructor.
A basic workflow after initializing looks as follows: For iOS 9+ / macOS 10.11+ only (ignore first two steps if you don't support iOS 9+ / macOS 10.11+):
Set desired value for `protocol` property if needed.
Asynchronously call loadInitialConfiguration.
Provide a custom VPNUOnDemandConnectionManager object for onDemandConnectionManager property if you want to manage VPN On Demand Rules.
Configure VPN server item using setupWithServerItem:successfullyInstalled: method.
Connect to the configured VPN server using startVPNWithError: method.
Disconnect at any time using stopVPNWithError: method.
You can check connectionStatus property of this class to know the real VPN connection status every time VPNUConnectionStatusDidChangeNotification notification is posted or simply use KVO.
This class is a public interface of a class cluster. You are discouraged from subclassing it. You MUST call loadInitialConfiguration method asynchronously if you are using iOS 9+ / macOS 10.11+ BEFORE any call to instance of this class.
Extends: NSObject
Declared in: VPNUConfigurator.h
+ (instancetype)configuratorWithTransport:(VPNUTransport *)transport;
An initialized VPN configurator object or nil if the object couldn't be created.
This method is a convenience constructor.
+ (BOOL)isNEVPNManagerSupportedByPlatform;
YES if current platform version supports NEVPNManager, NO otherwise.
For macOS this method returns YES for OS version starting from 10.11+. Although NEVPNManager is available for 10.10, it just doesn't work.
- (NSError *)enableVPN;
nil if VPN was enabled, error object otherwise.
If succeeded, this method disables VPN configurations of other apps. This method blocks a calling thread. This method shouldn't be called from main thread.
Available in Mac OS X v10.11. Available in iOS v8.0.
- (instancetype)initWithTransport:(VPNUTransport *)transport NS_DESIGNATED_INITIALIZER;
An initialized VPN configurator object or nil if the object couldn't be created.
- (BOOL)isOnDemandEnabled;
YES if VPN On Demand is turned on, NO otherwise.
This method return actual value from System Preferences.
- (BOOL)loadInitialConfiguration;
YES if load was successful, NO otherwise.
Call this method asynchronously to load default VPN manager for selected protocol if you are using this class on iOS 9+ / macOS 10.11 and support custom protocol. This method shouldn't be called from main thread.
Available in Mac OS X v10.11. Available in iOS v9.0.
- (NSError *)loadPreferences;
nil if preferences were loaded successfully, error object otherwise.
This method loads the preferences for VPN configuration of the current application. You can call this method if you want to retrieve connectionStatus property before any call to configurator. This method blocks a calling thread. This method shouldn't be called from main thread.
- (NSError *)removeProfile;
nil if removal was successful, error object otherwise.
This method blocks a calling thread. This method shouldn't be called from main thread.
- (NSError *)setOnDemandEnabled:(BOOL)enabled;
nil on success, error object otherwise.
This method blocks a calling thread. This method shouldn't be called from main thread.
- (NSError *)setupWithServerItem:(VPNUServerItem *)serverItem successfullyInstalled:(BOOL *)successfullyInstalled;
nil if setup was successful, error object otherwise.
This method first retrieves VPN profile information for the specified server item. If this step was succesful, it then tries to install a new VPN profile into the system using the information retrieved in the first step. If configuration downloaded for the server item is corrupted (e.g., has no server address) the profile is automatically deleted. This method blocks a calling thread. This method shouldn't be called from main thread.
- (BOOL)startVPNWithError:(NSError **)error;
YES if the VPN tunnel was started successfully, NO if an error occurred.
This method returns after VPN tunnel connection process is started and does not signals about the actual success of the VPN connection. In order to obtain the connection status, use the connectionStatus property. This method blocks a calling thread. This method shouldn't be called from main thread.
- (void)stopVPNWithError:(NSError **)error;
This method returns after VPN tunnel disconnect process is started and does not signals about the actual success of the VPN connection. In order to obtain the connection status, use the connectionStatus property. This method blocks a calling thread. This method shouldn't be called from main thread.
@property (copy) NSString *appScheme;
Application scheme used by local server.
@property (nonatomic, copy) NSString *customProfileDownloadHTMLPath;
An absolute path to your custom local HTML page which is shown to user during profile download process.
@property (copy) NSString *customProtocolProfileName;
Custom name for a downloaded VPN profile if Wise or OpenVPN is selected as protocol.
If not set - `profileName` is used.
@property (strong) VPNUOnDemandConnectionManager *onDemandConnectionManager;
If you want to manage VPN On Demand Rules using VPNUOnDemandConnectionManager, set its instance here.
If you don't set this value before configuring a new connection with setupWithServerItem: default On Demand rules will be applied for the connection.
@property (copy) NSString *profileName;
Custom name for a downloaded VPN profile.
@property VPNUProtocol protocol;
Protocol used when downloading and configuring VPN profile.
Set this property before calling setupWithServerItem:successfullyInstalled: method. Default value is VPNUProtocolIPSec.
@property BOOL useNEVPNManager;
Tells the configurator to use NEVPNManager class for configuring and controlling a VPN.
If set to YES, user will be able to turn a VPN connection on and off inside the host application. If set to NO, user will have to explicitly download profiles and turn a VPN connection on and off inside iOS Settings (pre-iOS8 style). Default value is YES.
@property (readonly, getter=isVPNEnabled) BOOL VPNEnabled;
This property is set to YES if VPN configuration for current app is enabled.
This property will be set to NO when other VPN configurations (from other apps) are enabled.