diff --git a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs index e550a6944563..a5753cff4b6c 100644 --- a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs +++ b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs @@ -7,7 +7,9 @@ internal partial class ConnectionProfile { internal static partial class NativeMethods { + [JSImport("globalThis.Windows.Networking.Connectivity.ConnectionProfile.hasInternetAccess")] + internal static partial bool HasInternetAccess(); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs index fb106533716d..5b0ff24b56f0 100644 --- a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs +++ b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs @@ -8,7 +8,9 @@ namespace Windows.Networking.Connectivity { public partial class ConnectionProfile { +#if !NET7_0_OR_GREATER private const string JsType = "Windows.Networking.Connectivity.ConnectionProfile"; +#endif internal static ConnectionProfile GetInternetConnectionProfile() => new ConnectionProfile(); @@ -19,9 +21,13 @@ private ConnectionProfile() private NetworkConnectivityLevel GetNetworkConnectivityLevelImpl() { +#if NET7_0_OR_GREATER + return NativeMethods.HasInternetAccess() ? NetworkConnectivityLevel.InternetAccess : NetworkConnectivityLevel.None; +#else var command = $"{JsType}.hasInternetAccess()"; var result = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command); return bool.Parse(result) ? NetworkConnectivityLevel.InternetAccess : NetworkConnectivityLevel.None; +#endif } } }