0

I want to connect to wifi.................................................................... Here is my code:

NEHotspotConfigurationManager wifiManager = new NEHotspotConfigurationManager();
var wifiConfig = new NEHotspotConfiguration(ssid, password, false) { JoinOnce = true };
wifiManager.RemoveConfiguration(ssid);
wifiManager.ApplyConfigurationAsync(wifiConfig);
wifiManager.ApplyConfiguration(wifiConfig, (error) =>
{
if (error != null)
{
Console.WriteLine($"Error while connecting to WiFi network {ssid}: {error.Description}");
}
});
return true;
Kefi
  • 67
  • 2
  • 7

1 Answers1

1

Just like @cole-xia-msft mentioned the link for the configuration work, the C# code would look like this.

var configuration = new NetworkExtension.NEHotspotConfiguration("SSID", "Password", false);
configuration.JoinOnce = true;

NetworkExtension.NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(configuration, (NSError error) => 
{
    if (error != null) {
        if (error?.LocalizedDescription == "already associated.")
            Console.WriteLine("Connected");
        else
            Console.WriteLine("No Connected");
    }
    else
        Console.WriteLine("Connected");
});

If your function enclosing the ApplyConfiguration call is asynchronous, you should consider using ApplyConfigurationAsync instead

Saamer
  • 4,687
  • 1
  • 13
  • 55