Skip to content

Commit f2f5b55

Browse files
authored
Merge pull request #21908 from ajpinedam/doc/update.networkactivity
docs: update network activity
2 parents 536a46f + 36bc321 commit f2f5b55

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

doc/articles/features/windows-networking.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,82 @@ uid: Uno.Features.WNetworking
55
# Networking
66

77
> [!TIP]
8-
> This article covers Uno-specific information for the `Windows.Networking` namespace. For a full description of the feature and instructions on using it, see [Windows.Networking Namespace](https://learn.microsoft.com/uwp/api/windows.networking).
8+
> This article provides specific information about Uno within the `Windows.Networking` namespace. For a comprehensive overview of the feature and guidance on how to use it, visit [Windows.Networking](https://learn.microsoft.com/uwp/api/windows.networking).
99
10-
* The `Windows.Networking` namespace provides classes for accessing and managing network connections from your app.
10+
The `Windows.Networking` namespace offers classes to access and manage network connections within your app.
1111

12-
## Supported features
12+
## NetworkInformation
13+
14+
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](https://learn.microsoft.com/uwp/api/windows.networking.connectivity.networkinformation).
15+
16+
### Supported features
1317

1418
| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
1519
|--------------------------------|---------|---------|-----|------------|-------|--------------|--------------|
1620
| `GetInternetConnectionProfile` ||||||||
1721
| `NetworkStatusChanged` ||||||||
1822

19-
## Checking Network Connectivity in Uno
23+
### Checking Network Connectivity in Uno
2024

2125
For more detailed guidance on network connectivity, watch our video tutorial:
2226

2327
> [!Video https://www.youtube-nocookie.com/embed/sK9IbkBAXIo]
2428
25-
## Platform-specific
29+
### Platform-specific
2630

27-
### Android
31+
#### Android
2832

29-
Android can recognize all values of `NetworkConnectivityLevel`. iOS, macOS, and WASM return either `None` or `InternetAccess`.
33+
Android recognizes all values of the `NetworkConnectivityLevel` [enum](https://learn.microsoft.com/uwp/api/windows.networking.connectivity.networkconnectivitylevel). In contrast, iOS, macOS, and WASM only return either `None` or `InternetAccess`.
3034

31-
The `android.permission.ACCESS_NETWORK_STATE` permission is required. It can be added to the application manifest or with the following attribute in the Android platform head:
35+
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:
3236

3337
```csharp
3438
[assembly: UsesPermission("android.permission.ACCESS_NETWORK_STATE")]
3539
```
3640

37-
### iOS/macOS reachability host name
41+
#### iOS/macOS reachability host name
42+
43+
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.
3844

39-
On iOS and macOS, an actual 'ping' request is necessary to verify internet connectivity. The default domain that is checked is `www.example.com`, but you can change this to be any other domain by setting the `WinRTFeatureConfiguration.NetworkInformation.ReachabilityHostname` property.
45+
```csharp
46+
WinRTFeatureConfiguration.NetworkInformation.ReachabilityHostname = "platform.uno";
47+
```
4048

41-
## Example
49+
### Example
4250

43-
### Checking for internet connectivity
51+
#### Checking for internet connectivity
4452

45-
You can use the following snippet to check for internet connectivity level in a cross-platform manner:
53+
Use the snippet below to check internet connectivity levels in a cross-platform manner.
4654

4755
```csharp
56+
using Windows.Networking.Connectivity;
57+
4858
var profile = NetworkInformation.GetInternetConnectionProfile();
49-
if (profile == null)
50-
{
51-
// No connection
52-
}
53-
else
59+
var level = profile?.GetNetworkConnectivityLevel();
60+
if (level is NetworkConnectivityLevel.InternetAccess)
5461
{
55-
var level = profile.GetNetworkConnectivityLevel();
56-
// level is a value of NetworkConnectivityLevel enum
62+
// Connected to the internet
5763
}
5864
```
5965

60-
### Observing changes in connectivity
66+
#### Observing changes in connectivity
6167

62-
You can use the following snippet to observe changes in connectivity:
68+
Use the following snippet to observe changes in connectivity:
6369

6470
```csharp
71+
using Windows.Networking.Connectivity;
72+
6573
NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
6674

6775
private void NetworkInformation_NetworkStatusChanged(object sender)
6876
{
69-
// Your implementation here
77+
// read the current connectivity state/level
78+
var profile = NetworkInformation.GetInternetConnectionProfile();
79+
var level = profile?.GetNetworkConnectivityLevel();
7080
}
7181
```
7282

73-
### Unsubscribing from the changes
83+
#### Unsubscribing from the changes
7484

7585
```csharp
7686
NetworkInformation.NetworkStatusChanged -= NetworkInformation_NetworkStatusChanged;

0 commit comments

Comments
 (0)