如何检测是否安装了 NEVPNManager 配置?

How to detect if NEVPNManager configuration is installed?

我正在使用 NetworkExtension 框架在 iOS 上使用 VPN。我能够安装配置并建立连接。我的问题是是否有办法检测 VPN 配置是否仍在安装或检测用户是否已卸载配置?

我不一定要在后台寻找通知或任何东西,但我要找的是 method/workaround 当应用程序被带到前台时我做的一些事情?

我正在使用中间 CA 颁发的证书进行证书身份验证,并尝试了此处的 'evaluating trust' 方法:Check if a configuration profile is installed on iOS

这对我不起作用。我总是被信任。我也试过这个:

if([NEVPNManager sharedManager].protocol){
   //installed
}else{
   //not installed
}

但这也行不通。卸载后协议仍然有效。如果我退出并重新启动应用程序,则协议无效。

如有任何建议,我们将不胜感激。

可能有点晚了。但是我遇到了同样的问题。但是,您的方法使我朝着正确的方向前进。您应该在以下的完成处理程序中加载它:loadFromPreferencesWithCompletionHandler

在我看来,检查是否安装了配置文件的正确用法是:

   manager = [NEVPNManager sharedManager];

   [manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
       if (manager.protocol == nil) {
           NSLog(@"Profile is not installed, you might want to install a profile");
       } else {
           NSLog(@"Profile is installed. It looks like this: %@",manager.protocol);
       }
   }];

您可以尝试关注

if ([[[NEVPNManager sharedManager] connection] status] == NEVPNStatusInvalid) {
    //...
}