I tried to call PacketTunnelProvider in my code …
I presume your PacketTunnelProvider is a subclass of NEPacketTunnelProvider. In that case, you don’t call that class directly. Rather, it is the principal class of your packet tunnel provider extension.
Remember that a VPN app has two targets:
The app itself, which is run by the user like any other app. It uses NETunnelProviderManager to configure and control the VPN.
The packet tunnel provider extension, which is invoked by the system when it wants to do VPN stuff. That extension has a principal class, your subclass of NEPacketTunnelProvider, that implements the custom logic associated with your VPN.
So your app does not call your NEPacketTunnelProvider subclass directly. Rather, your app configures the VPN using NETunnelProviderManager and then the system does the work to start your extension and call your NEPacketTunnelProvider subclass within the context of that extension. This can happen as the result of direct action on your app’s part (for example, if you call
-startTunnelWithOptions:
on the NETunnelProviderSession associated with your NETunnelProviderManager) but it can also happen behind the scenes (for example, if your VPN supports VPN On Demand).
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"