Windows UWP -> Application.internetReachability Broken?

Hello!

I’m running some tests on the final build of my game and just noticed that Application.internetReachability is not working as it used to.

When running the UWP build, turning off Wi-Fi or turning on Airplane Mode would always return NotReachable but now it’s returning ReachableViaLocalAreaNetwork

When running in the editor, the correct behaviour is observed.

Tested on the following setup…

Windows 10 (19042.844)
Unity 2019.4.21f1
Master x64

Did it work in a previous Unity version? Or just at some point in time before? I’ve looked at the source code and the implementation for UWP hasn’t been touched since 2014.

Internally, we call Windows::Networking::Connectivity::NetworkInformation::GetHostNames(), and if any are found, we return ReachableViaLocalAreaNetwork. We also distinguish between carrier network and local area network depending on the interface type.

However, if it doesn’t match what you see in the editor, could you file a bug report? We want to potentially fix it.

It did yes, 100% sure of that.

I’ve protected any code that requires online access (i.e. IAP) with an online check. I used to test it by enabling airplane mode.

To be honest, it’s been months since I last tested that particular feature and I’ve installed many Unity & Windows updates since then. It could very well be anyone one of those. I’m assuming the editor & runtime make the same internal WinAPI calls?

Running a UWP build…

Image1 = Online
Image2 = Airplane Mode

But as you can see, the debug log shows the same result.

6877601--803249--Image1.png
6877601--803252--Image2.png

Running in the editor…

Image3 = Airplane Mode

So I’m seeing the correct behaviour.

6877622--803261--Image3.png

No, the editor uses INetworkListManager, which isn’t available on UWP.

Anyway, the way we check for it in UWP isn’t great. A better way to do this, would be ConnectionProfile::GetNetworkConnectivityLevel. Can you report a bug on this so we could fix it?

To workaround, you can call that API from script directly:

static bool IsInternetAvailable()
{
#if !UNITY_WSA || UNITY_EDITOR
    return Application.internetReachability != NetworkReachability.NotReachable;
#else
    var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
    if (connectionProfile == null)
        return false;

    returm connectionProfile == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess;
#endif
}
1 Like

Thanks for feedback, it’s much appreciated.

Spotted a few typos in the code, but fixed them and can confirm this is working well in a UWP build.

The revised code is…

static bool IsInternetAvailable()
{
#if !UNITY_WSA || UNITY_EDITOR
    return Application.internetReachability != NetworkReachability.NotReachable;
#else
    var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
    if (connectionProfile == null)
      return false;
    return connectionProfile.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess;
#endif
}

I’ll look into reporting it, but no promises as literally have a list of a hundred things to-do leading up-to launch.

Thanks again.

Sorry for the typos, typed it directly into the forum post without trying to build it :smile:.

1 Like

No need to apologise. Impressed you typed it by hand and it was pretty much spot on.

I haven’t touched UWP in about 5 years, so am rusty and grateful for the workaround :slight_smile:

Hello!!

Any update on this?

I have the same result using:

Windows 10 19041.1052
Unity 2020.3.3f1
Release x64

The workaround works as it should be, Thanks!!

I think this fell out of our radar. I don’t think we ever received a bug report.

Does it worths it to do a bug report? most (or all) of the functionalities for UWP can be called directly from the WinRT APIs, but I thing a bug report can make you guys have a look on this kind of things.

Most of the info related with Unity/UWP seems out of date (on windows docs side too) and with the intro of Windows 11 this feels like we (unity users) are out of the race. I think UWP is a really good platform for games and apps.

Saludos.

Yes, bug reports are definitely very useful. They make sure that the issue is logged, can be searched for on issuetracker.unity3d.com. Also, we cannot really forget about things that are logged as bugs.

I’m not quite sure what you mean by this? Windows 11 shouldn’t really change anything for developers AFAIK.

Apologies @Tautvydas-Zilys

I was side-tracked at the time then completely forgot :roll_eyes:

I’ll try and submit one before the weekend.

Hi @Tautvydas-Zilys ,

This has been reported as case 1351079

Apologies for taking so long.

Thanks for the report!

1 Like

The fix landed to 2021.2.6f1 and 2020.3.25f1.

1 Like

Many thanks @Tautvydas-Zilys :slight_smile:

I’ll test it with 2020.3.25f1 as soon as it’s released and will report back if there are any issues.

Thanks @Tautvydas-Zilys Tested in 25f1 and can confirm it’s now working :slight_smile:

1 Like