doc/articles/features/windows-networking.md
[!TIP] This article provides specific information about Uno within the
Windows.Networkingnamespace. For a comprehensive overview of the feature and guidance on how to use it, visit Windows.Networking.
The Windows.Networking namespace offers classes to access and manage network connections within your app.
The Windows.Networking.Connectivity.NetworkInformation class provides access to network connection information and allows you to monitor changes in network connectivity. For more details, refer to the official documentation: NetworkInformation Class.
| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
|---|---|---|---|---|---|---|---|
GetInternetConnectionProfile | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
NetworkStatusChanged | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
For more detailed guidance on network connectivity, watch our video tutorial:
Android recognizes all values of the NetworkConnectivityLevel enum. In contrast, iOS, macOS, and WASM only return either None or InternetAccess.
The android.permission.ACCESS_NETWORK_STATE permission is necessary and must be included in the application manifest or specified using the following attribute in the Android platform head:
[assembly: UsesPermission("android.permission.ACCESS_NETWORK_STATE")]
iOS and macOS use a 'ping' request to check internet connectivity. The default domain is www.example.com; however, you can change it to any other domain by setting the WinRTFeatureConfiguration.NetworkInformation.ReachabilityHostname property.
WinRTFeatureConfiguration.NetworkInformation.ReachabilityHostname = "platform.uno";
Use the snippet below to check internet connectivity levels in a cross-platform manner.
using Windows.Networking.Connectivity;
var profile = NetworkInformation.GetInternetConnectionProfile();
var level = profile?.GetNetworkConnectivityLevel();
if (level is NetworkConnectivityLevel.InternetAccess)
{
// Connected to the internet
}
Use the following snippet to observe changes in connectivity:
using Windows.Networking.Connectivity;
NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
private void NetworkInformation_NetworkStatusChanged(object sender)
{
// read the current connectivity state/level
var profile = NetworkInformation.GetInternetConnectionProfile();
var level = profile?.GetNetworkConnectivityLevel();
}
NetworkInformation.NetworkStatusChanged -= NetworkInformation_NetworkStatusChanged;