Vili
Vili

Reputation: 908

Using NEHotspotConfigurationManager to connect to a wifi with no internet

I am having difficulties connecting to a wifi with no internet connection on my iOS device. The internet connection is missing by design as the app is used to control devices in the network and no external connection to internet is available.

IPhone I am using is version 12.1. Xamarin.IOS is 11.14 and Xamarin.Forms 3.3.0

The connection is made successfully and I get prompt

"appname" wants to join Wi-Fi Network "ssid"?

but after selecting Join nothing happens. After when I go to Settings - Wifi page I get a page with title Log In and the page just says that the router (asus) has wan turned off. If I select Cancel I can select "Use Without Internet" and then I am connected.

Even after making the connection I still can't connect to a device in the network (by pinging it) not sure if that is still the same issue or not.

App is written using Xamarin.Forms and here is the part where the connection is created.

    public void ConnectToWifi(string ssid, string password)
    {
        using (var _wifiManager = new NEHotspotConfigurationManager())
        {

            var wifiConfig = new NEHotspotConfiguration(ssid, password, false)
            {
                JoinOnce = true
            };

            _wifiManager.ApplyConfiguration(wifiConfig, error => CompletionHandler(error, ssid));

        }

    }

    private void CompletionHandler(NSError error, string ssid)
    {
        if (error != null)
        {
            Console.WriteLine($"Error while connecting to WiFi network {ssid}: {error}");
        }
    }

Upvotes: 0

Views: 771

Answers (1)

Vili
Vili

Reputation: 908

I found (a workaround for) the problem. It was how the iOS handles Asus WAN down browser redirect notice. It responds with a browser redirect and iOS thinks it is an login. I had to set the Enable WAN down browser redirect notice to false in the router Administration settings and then it worked as it should. Problem remains if and when we don't have administrative rights to the router.

Upvotes: 0

Related Questions