I need to detect whether iphone is connected to VPN or not, programatically. I am developing a app which try to load URL, this page open only when device is connected to VPN. Before loading this URL I need to check VPN connectivity. I tried the following . But this is not working as expected.
- (BOOL)checkForVPNConnectivity {
NSDictionary *dict = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
//NSLog(@"cfnetwork proxy setting : %@", dict);
return [dict count] > 0;
}
CFNetworkCopySystemProxySettings
returning when VPN is connected vs when VPN is not connected? You say it's "not working as expected", but you don't say what it's doing. – CalcariferousCFNetworkCopySystemProxySettings
, as well. But for me, I see zero entries when on cellular, but a couple of entries whenever I'm on my home wifi (but not VPN in either scenario). Bottom line, the presence or absence of entries, alone, is clearly not a valid way of detecting VPN. Hopefully theSystemConfiguration.framework
suggestion, below, will be more promising. – Calcariferous