I have an iOS app which contains a Network Extension that subclasses the NEPacketTunnelProvider
, acting as a packet-tunnel VPN. After deploying the app on the device as a regular app, it runs the following code fragment:
NETunnelProviderManager.loadAllFromPreferences { managers, _ in
self.manager = managers?.first ?? NETunnelProviderManager()
self.manager.protocolConfiguration = getConfiguration()
self.manager.saveToPreferences { error in
// Handle errors or show a "Connect" button in the UI
}
}
This asks the user to install the extension as a "Device VPN". I can then use try? self.manager?.connection.startVPNTunnel()
to start the VPN (and later stop it when needed). So far, this works fine.
Now, I want to deploy the app with an MDM and set it up as the "custom VPN" of a "Per-App VPN". I have tested the setup using
- a real MDM, AND
- using the "development" setup described in NETunnelProviderManager.
In both cases, the "Per-App VPN" shows up as a VPN in the "Settings" app.
However, in both cases I am unable to retrieve, configure or use the "Per-App VPN". The code fragment posted above returns no NETunnelProviderManager
at all. When instantiating one on my own and triggering self.manager.saveToPreferences()
, it queries the user to install a "Device VPN". While I can control and use the latter, this is clearly not what I want after having gone through the pain of installing the "Per-App VPN".
How can I retrieve the NETunnelProviderManager
of the "Per-App VPN"? And then use it to configure and control the VPN connection? (Ideally, I would like to use the same app and the same Network Extension for both use cases, leaving the choice of which VPN type to use to the user or the user's MDM administrator.)