swiftxcodenetworkextension

NETunnelProviderManager loadAllFromPreferences zero manager returns


I'm trying to configure NetworkExtension VPN and in the beginning when I try to get NETunnelProviderManagers, I get zero managers with no errors.

NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
        guard error == nil else {
            print("Error loading all NETunnelProviderManager Preferences", error?.localizedDescription as Any)
            return
        }
        guard managers?.count != 0 else {
            print("No provider managers was found")
            return
        }
        self.providerManager = NETunnelProviderManager()
        self.providerManager = managers?.first
        self.setup()
}

Solution

  • To get managers, you first need to create a manager and save it by calling saveToPreferences()

    If this is the function in which you want to create a manager, remove those lines:

    guard managers?.count != 0 else {
        print("No provider managers was found")
        return
    }