我想连接到wifi ..................................................... ........................... 这是我的代码:
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;
答案 0 :(得分:0)
就像@ cole-xia-msft提到了配置work的链接一样,C#代码看起来像这样。
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");
});
如果包围ApplyConfiguration
调用的函数是异步的,则应考虑改用ApplyConfigurationAsync