Last active
July 17, 2024 03:16
-
-
Save PramodJoshi/4faad4c91f7dcb4eb9b06be8390c01db to your computer and use it in GitHub Desktop.
Check VPN connection on iOS devices - Swift 3/4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better to replace
==
with a search for substring askey
could take different values. eg, utun5