I wanted to check VPN connection is there or not. I found code in Swift but I can not use NEVPNStatus in Objective-C:
func checkNEStatus( status:NEVPNStatus ) {
switch status {
case NEVPNStatus.Invalid:
print("NEVPNConnection: Invalid")
case NEVPNStatus.Disconnected:
print("NEVPNConnection: Disconnected")
case NEVPNStatus.Connecting:
print("NEVPNConnection: Connecting")
case NEVPNStatus.Connected:
print("NEVPNConnection: Connected")
case NEVPNStatus.Reasserting:
print("NEVPNConnection: Reasserting")
case NEVPNStatus.Disconnecting:
print("NEVPNConnection: Disconnecting")
}
}
I am using below code for Objective-C: but it doesn't work in some of Chinese network device. They are sending "TUN" if the network is still not using vpn.
- (BOOL)isVPNConnected
{
NSDictionary *dict = CFBridgingRelease(CFNetworkCopySystemProxySettings());
NSArray *keys = [dict[@"__SCOPED__"]allKeys];
NSLog(@"keys==>%@",keys);
for (NSString *key in keys) {
if ([key rangeOfString:@"tap"].location != NSNotFound ||
[key rangeOfString:@"tun"].location != NSNotFound ||
[key rangeOfString:@"ipsec"].location != NSNotFound ||
[key rangeOfString:@"ppp"].location != NSNotFound){
return YES;
}
}
return NO;
}
Add observer in your ViewDidLoad to get the VPN Status.