Post not yet marked as solved
Post marked as unsolved with 3 replies, 1,715 views
Is there any reliable way to check for an active VPN connection or a connection over Personal Hotspot?
I am currently building an app that uses MultipeerConnectivity for peer-to-peer communication and from what I have learned so far MPC does not work with VPN / Personal Hotspot turned on.
To provide a first-class user experience (and tackle VPN problems in App Review) I want to check for a VPN / Personal Hotspot connection and display the user an alert encouraging him to disable the corresponding connection.
Just like AirDrop which should work quite similar to MPC.
I found this code snippet on Stackoverflow - https://stackoverflow.com/questions/34794255/ but since I do not really now anything about network interfaces in iOS I came here to seek help. :)
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
}