Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
How to remove all existing managers from NETunnelProviderManager?

I have come across a problem when using a NetworkExtension in Swift to utilise OpenVPN or Wireguard with the NETunnelProviderManager.

I have the following code in the ViewDidLoad of my mainViewController. I don't load it twice, and it works fine when using the Apple integrated IKEv2.

NotificationCenter.default.removeObserver(self, name: NSNotification.Name.NEVPNStatusDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(vpnStatusDidChange(_:)), name: NSNotification.Name.NEVPNStatusDidChange, object: nil)

But when I use OpenVPN or Wireguard via the Networkextension, these network-status-change-events keep firing n+1. First time it fires once. Second time I connect and disconnect, I see the network-statuses firing twice, then three times etc.

I have been researching a lot and it seems the problem is in the code below:

func loadTunnelProviderManager(completion:@escaping () -> Void) {
        NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
            if error == nil {
                self.tunnelProviderManager = managers?.first ?? NETunnelProviderManager()
                completion()
            }
        }
    }

If I don't retrieve managers?.first and instantiate it each time instead:

self.tunnelProviderManager = NETunnelProviderManager()

Then the issue is resolved. However every time I connect to the VPN, inevitably a new VPN config is also created in the settings, which is not ideal.

TL;DR

Long story short, how do I delete all existing managers before instantiating a new NETunnelProviderManager? I know this might go against the convention, but it will solve the issue.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!