NETunnelProviderManager loadAllFromPreferences 零管理器 returns

NETunnelProviderManager loadAllFromPreferences zero manager returns

我正在尝试配置 NetworkExtension VPN,一开始当我尝试获取 NETunnelProviderManagers 时,我得到了零个管理器,没有任何错误。

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()
}

要获取管理器,您首先需要创建一个管理器并通过调用 saveToPreferences() 保存它

如果这是您要在其中创建经理的函数,请删除这些行:

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