dotnet/maui

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

Open

#21,873 建立於 2024年4月17日

在 GitHub 查看
 (0 留言) (1 反應) (0 負責人)C# (23,245 star) (1,951 fork)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.

貢獻者指南