I have some questions regarding life cycle of Packet Tunnel Provider: I have some static vars at the PacketTunnelProvider. The user connected to the VPN, then disconnected, so I called the relevant compilation handler. After some time, the user will start VPN again, PacketTunnelProvider will be recreated.
- Will it use the same class as before, and all static vars will hold their last value? Or would it create a new PacketTunnelProvider?
- Is it the same behavior for Network Extension vs System Extension?
- Is it the same behavior for macOS vs iOS?
- What about running threads? If I created a thread, and then I called the completion handler, will this thread continue to run?
P.S If I'm adding exit(0) before 'quitting' the Packet Tunnel Provider, it will force cleaning the memory. But I guess it's not a good behavior for a System Extension to use exit(0)
class PacketTunnelProvider: NEPacketTunnelProvider {
static var isInitiated = false
...
}
override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
...
PacketTunnelProvider.isInitiated = true
...