4

I am working with VPN on iOS using the NetworkExtension framework. I am able to install the config and make connection. My question is if there's a way to detect if the VPN config is still installed or detect if user has un-installed the config?

I am not necessarily looking for a notification or anything in the background but what I am looking for is some method/workaround that I do when the application is brought to foreground?

I'm using certificate authentication with a certificate issued by an intermediate CA and have tried 'evaluating trust' method from here: Check if a configuration profile is installed on iOS

This did not work for me. I always comes to be trusted. I have also tried this:

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

But this also does not work. After uninstallation the protocol remains valid. If I quit and relaunch the app then the protocol is invalid.

Any suggestions are appreciated.

puru020
  • 808
  • 7
  • 20

2 Answers2

6

You can try following

if ([[[NEVPNManager sharedManager] connection] status] == NEVPNStatusInvalid) {
    //...
}
Warif Akhand Rishi
  • 23,920
  • 8
  • 80
  • 107
Timur Suleimanov
  • 435
  • 5
  • 16
  • You are right, this is the way to check. Though, on iOS 9 because of an iOS bug you have to call 'enableConfiguration' method 2 times in order for the above to work. – puru020 Dec 04 '17 at 03:22
1

Might be a little late. But i've encountered the same problem. However, your approach got me in the right direction. You should load it within the completion handler of: loadFromPreferencesWithCompletionHandler

The propper use, in my opinion, of checking if there is a profile installed:

   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);
       }
   }];
Benjamin de Bos
  • 4,334
  • 4
  • 20
  • 30
  • Does your application run in background (you don't have UIApplicationExitsOnSuspend key in Info.plist). My application does. What I have seen is that when the app does not exit when backgrounded, and the profile is installed the protocol remains valid. If you kill the app and re-launch then protocol is invalid. – puru020 Jun 22 '15 at 16:54
  • 1
    It is not work for me.After uninstallation the protocol remains valid. If I quit and relaunch the app then the protocol is invalid. – bronze man Sep 03 '15 at 11:20
  • 1
    There's an issue with [[NEVPNManager sharedManager]protocol] for iOS 8. If user declines to install profile, then [[NEVPNManager sharedManager]protocol] won't be nil even though VPN profile isn't installed in system. On iOS 9 code above works fine. What to do with iOS 8 - i have no idea. – Timur Suleimanov Oct 07 '15 at 11:56