0

I have an app, developed in Xamarin Forms, which connects programmatically to a WIFI (with no internet access) exposed by an IoT device.

This is the code I use to connect to the wifi network:

NEHotspotConfiguration configuration = new NEHotspotConfiguration("ssid");
Device.BeginInvokeOnMainThread(() =>
{
    NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(configuration, (NSError error) =>
    {
        if (error != null)
        {
            if (error.LocalizedDescription == "already associated.")
            {
                // connected!
                CommunicateConnected();
            }
            else
            {
                // not connected
                CommunicateNotConnected();
            }
        }
        else
        {
            // connected!
            CommunicateNotConnected();
        }
    });
});

Once the connection is successfully established the app performs some HTTP calls to the IP of the IoT device.
Sometimes it happens that the HTTP calls go over the cellular data connection instead of WIFI connection (because the joined network has no internet connection?) and they fail. (Simply, I see that the 4G icon is still visible instead of the one representing the WIFI connection). The switch between mobile connection and WIFI connection, in these cases, happen after some minutes.

Is there a way to force the HTTP calls to go over the just joined network?

giani.sim
  • 257
  • 2
  • 16
  • you can use [Connectivity](https://learn.microsoft.com/en-us/xamarin/essentials/connectivity?tabs=android#api) to monitor for changes in the connection state, and only issue calls when WiFi is active – Jason Feb 01 '22 at 19:40
  • That could take several minutes before switching from cellular to wifi. I don't want tohe user to wait so long before allowing interaction with IoT device. I would like to find a way to force http calls to be performed over WIFI – giani.sim Feb 02 '22 at 08:59

1 Answers1

0

You can set cellular data use for apps and services.

Go to Settings > Cellular, then turn Cellular Data on or off for any app (such as Maps) or service (such as Wi-Fi Assist) that can use cellular data.

If a setting is off, iPhone uses only Wi-Fi for that service.

Note:

Wi-Fi Assist is on by default. If Wi-Fi connectivity is poor, Wi-Fi Assist automatically switches to cellular data to boost the signal. Because you stay connected to the internet over cellular when you have a poor Wi-Fi connection, you might use more cellular data, which may incur additional charges depending on your data plan. See the Apple Support article About Wi-Fi Assist.

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19