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+ only (ignore first two steps if you don't support iOS 9+):
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
:alreadyInstalled: method.
Connect to the configured VPN server using startVPNWithError
: method.
Disconnect at any time using stopVPNWithError
: method.
You should check connectionStatus
property of this class to know the real VPN connection status every time VPNUConnectionStatusDidChangeNotification
notification is posted.
attention: You MUST call loadInitialConfiguration
method asynchronously if you are using iOS 9+ 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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (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.
Not available in Mac OS X. 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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (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+ and support custom protocol.
This method shouldn't be called from main thread.
Not available in Mac OS X. 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.
Not available in Mac OS X. Available in iOS v8.0.
- (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.
Not available in Mac OS X. Available in iOS v8.0.
- (NSError *)setOnDemandEnabled:(BOOL)enabled;
YES
VPN On Demand is turned on, otherwise VPN On Demand is turned off.nil
on success, error object otherwise.
This method blocks a calling thread.
This method shouldn't be called from main thread.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (NSError *)setupWithServerItem:(VPNUServerItem *)serverItem alreadyInstalled:(BOOL *)alreadyInstalled;
nil
.YES
, if VPN profile is already installed.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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (BOOL)startVPNWithError:(NSError **)error;
nil
.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.
connectionStatus
Available in Mac OS X v10.7. Available in iOS v8.0.
- (void)stopVPNWithError:(NSError **)error;
nil
.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.
connectionStatus
Available in Mac OS X v10.7. Available in iOS v8.0.
@property (copy) NSString *appScheme;
Application scheme used by local server.
Available in Mac OS X v10.7. Available in iOS v8.0.
@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.
Available in Mac OS X v10.7. Available in iOS v8.0.
@property (copy) NSString *profileName;
Custom name for a downloaded VPN profile.
Available in Mac OS X v10.7. Available in iOS v8.0.
@property VPNUProtocol protocol;
Protocol used when downloading and configuring VPN profile.
Set this property before calling setupWithServerItem
:alreadyInstalled: method. Default value is VPNUProtocolIPSec
.
Available in Mac OS X v10.7. Available in iOS v8.0.
@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
.
Available in Mac OS X v10.7. Available in iOS v8.0.
@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.
Available in Mac OS X v10.7. Available in iOS v8.0.
typedef NS_ENUM(NSInteger, VPNUConnectionStatus) { VPNUConnectionStatusInvalid = 0, VPNUConnectionStatusDisconnected = 1, VPNUConnectionStatusConnecting = 2, VPNUConnectionStatusConnected = 3, VPNUConnectionStatusReasserting = 4, VPNUConnectionStatusDisconnecting = 5, } NS_ENUM_AVAILABLE( 10_7, 8_0);