Class

NEVPNManager

NEVPNManager is used to create and manage VPN configurations and to control the resulting VPN tunnel connections.

Declaration

class NEVPNManager : NSObject

Overview

Each application is allowed to create a single VPN configuration. The NEVPNManager class has a class method (NEVPNManager) that provides access to a single NEVPNManager instance. This single instance corresponds to a single VPN configuration as displayed in the VPN Settings panel in the Settings app on iOS and the Network Preferences pane in the System Preferences application in macOS.

The VPN configuration created by the NEVPNManager instance is classified as a Personal VPN configuration. On both iOS and macOS, Non-Personal VPN configurations take precedence over Personal VPN configurations. If both a Personal VPN configuration and a Non-Personal VPN configuration are connected simultaneously, and both VPN tunnels are configured to act as the default route that network traffic takes to reach the Internet, then the Non-Personal VPN tunnel will actually be the default route to the Internet for as long as it is connected.

Use of the NEVPNManager class requires the com.apple.developer.networking.vpn.api entitlement. You can get this entitlement for your app by enabling the "Personal VPN" capability for your app in Xcode.

The VPN configuration managed by NEVPNManager is stored in the Network Extension preferences which are managed by the Network Extension framework. The VPN configuration must be explicitly loaded into memory from the Network Extension preferences before it can be used, and any changes made to the configuration must be explicitly saved to the Network Extension preferences before taking effect on the system.

Instances of this class are thread safe.

Topics

Managing the VPN Configuration

class func shared() -> NEVPNManager

Access the single instance of NEVPNManager.

func loadFromPreferences(completionHandler: (Error?) -> Void)

Load the VPN configuration from the Network Extension preferences.

func saveToPreferences(completionHandler: ((Error?) -> Void)? = nil)

Save the VPN configuration in the Network Extension preferences.

func removeFromPreferences(completionHandler: ((Error?) -> Void)? = nil)

Remove the VPN configuration from the Network Extension preferences.

Set the VPN Configuration Parameters

var onDemandRules: [NEOnDemandRule]?

An ordered list of Connect On Demand rules

var isOnDemandEnabled: Bool

A Boolean used to toggle the Connect On Demand capability.

var localizedDescription: String?

A string containing the display name of the VPN configuration.

var `protocol`: NEVPNProtocol?

An NEVPNProtocol object containing the configuration settings of the VPN tunneling protocol.

Deprecated
var isEnabled: Bool

A Boolean used to toggle the enabled state of the VPN configuration.

var protocolConfiguration: NEVPNProtocol?

An NEVPNProtocol object containing the configuration settings of the VPN tunneling protocol.

Control the VPN connection

var connection: NEVPNConnection

An NEVPNConnection object that is used to control the VPN tunnel specified by the VPN configuration.

Notifications

static let NEVPNConfigurationChange: NSNotification.Name

Posted after the VPN configuration stored in the Network Extension preferences changes.

Entitlements

Personal VPN Entitlement

The API an app can use to create and control a custom system VPN configuration.

Key: com.apple.developer.networking.vpn.api

Relationships

Inherits From

Conforms To