Ability to detect whether we are connected via a VPN on iOS
#21,873 opened on Apr 17, 2024
Description
Description
I work on an Android/iOS app that we recently ported from Xamarin to MAUI. Our application requires the ability to detect whether the user is connected via a VPN. This is possible on Android via
ConnectivityManager.GetNetworkCapabilities(connectivityManager.ActiveNetwork).HasTransport(TransportType.Vpn)
On Xamarin, we implemented the iOS VPN detection like so:
var settings = (CFProxySettings) CFNetwork.GetSystemProxySettings();
var keys = settings.Dictionary.ValueForKey(new NSString("__SCOPED__")) as NSDictionary;
string[] vpnProtocols = { "tap", "tun", "utun2", "ppp", "ipsec", "ipsec0" };
return keys.Any(k => vpnProtocols.Any(v => k.Key.ToString().Contains(v)));
as per https://stackoverflow.com/questions/54932217/getting-vpn-connection-status-on-xamarin-ios
However, on MAUI, the CFNetwork.GetSystemProxySettings() method is missing. Is there an alternative way to detect this, or could I request the restoration of this API?
Public API Changes
CFNetwork.GetSystemProxySettings() // as per CoreFoundation in Xamarin.iOS.dll
Intended Use-Case
Detecting VPN connection to improve connectivity management.