Skip to content

Instantly share code, notes, and snippets.

@PramodJoshi
Last active July 17, 2024 03:16
Show Gist options
  • Save PramodJoshi/4faad4c91f7dcb4eb9b06be8390c01db to your computer and use it in GitHub Desktop.
Save PramodJoshi/4faad4c91f7dcb4eb9b06be8390c01db to your computer and use it in GitHub Desktop.
Check VPN connection on iOS devices - Swift 3/4
func isVPNConnected() -> Bool {
let cfDict = CFNetworkCopySystemProxySettings()
let nsDict = cfDict!.takeRetainedValue() as NSDictionary
let keys = nsDict["__SCOPED__"] as! NSDictionary
for key: String in keys.allKeys as! [String] {
if (key == "tap" || key == "tun" || key == "ppp" || key == "ipsec" || key == "ipsec0") {
return true
}
}
return false
}
@thafer-cs
Copy link

Better to replace == with a search for substring as key could take different values. eg, utun5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment