dotnet/maui

Ability to detect whether we are connected via a VPN on iOS

Open

#21,873 opened on 2024年4月17日

GitHub で見る
 (0 comments) (1 reaction) (0 assignees)C# (23,245 stars) (1,951 forks)batch import
area-essentialsgood first issueproposal/open

説明

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.

コントリビューターガイド

Ability to detect whether we are connected via a VPN on iOS · dotnet/maui#21873 | Good First Issue