private int ConnectWpa(string ssid, string pass) { try { var wifiConfig = new NEHotspotConfiguration(ssid, pass, false) { JoinOnce = true }; var wifiManager = new NEHotspotConfigurationManager(); wifiManager.ApplyConfiguration(wifiConfig, (error) => { if (error != null) { Console.WriteLine($"Error while connecting Wifi network {ssid}:{error}"); } }); Console.WriteLine("Connected!"); return(1); } catch (Foundation.NSErrorException ext) { Console.WriteLine(ext.ToString()); return(0); } catch (Exception ext) { Console.WriteLine(ext.ToString()); return(0); } }
public static Task Connect(string ssid, string password) { NEHotspotConfiguration configuration; if (string.IsNullOrEmpty(password)) { configuration = new NEHotspotConfiguration(ssid); } else { configuration = new NEHotspotConfiguration(ssid, password, false); } configuration.JoinOnce = true; TaskCompletionSource <bool> source = new TaskCompletionSource <bool>(); NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(configuration, async err => { if (err == null) { // Wait a bit for connection to fully establish await Task.Delay(1000); source.TrySetResult(true); } else { Debug.WriteLine(err.Description); source.TrySetResult(false); } }); return(source.Task); }
public void SetHotSpot(bool on) { var hotspotNetwork = new NEHotspotNetwork(); var hotspotConfiguration = new NEHotspotConfiguration("wifi name", "wifi password", false) { JoinOnce = true }; NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(hotspotConfiguration, null); }
public bool Connect(string ssid, string password) { bool ret = false; try { var wifiManager = new NEHotspotConfigurationManager(); var wifiConfig = new NEHotspotConfiguration(ssid, password, false); wifiManager.ApplyConfiguration(wifiConfig, (error) => { ret = error == null; }); } catch (Exception ex) { } return(ret); }
public override async Task <bool> Connect(string essid, string passphrase) { OnStatusUpdated("Connecting to WiFi"); var manager = NEHotspotConfigurationManager.SharedManager; var conf = new NEHotspotConfiguration(essid, passphrase, false); conf.JoinOnce = false; if (!await manager.ApplyConfigurationAsync(conf).ContinueWith(t => t.Exception == null)) { return(false); } OnStatusUpdated("Waiting for connection"); await WaitForConnection(); return(true); }
public async Task <bool> ConnectToSecuredWifiNetwork(string ssid, string passphrase) { try { var hotspotConfig = new NEHotspotConfiguration(ssid, passphrase, false); await NEHotspotConfigurationManager.SharedManager.ApplyConfigurationAsync(hotspotConfig); return(true); } catch (Exception e) { logger.Log(e, "Failed to connect to hotspot"); return(false); } }
public void ConnectToWifi(string ssid, string password) { var wifiManager = new NEHotspotConfigurationManager(); var wifiConfig = new NEHotspotConfiguration(ssid, password, false); wifiManager.ApplyConfiguration(wifiConfig, (error) => { if (error != null) { //var dismissed = UIAlertAction(); var alert = UIAlertController.Create(ssid, password, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, (UIAlertAction obj) => { })); var rootVC = UIApplication.SharedApplication.Windows[0].RootViewController; rootVC.PresentViewController(alert, true, null); Console.WriteLine($"Error while connecting to WiFi network {ssid}: {error}"); } }); }
async partial void OnConnectClicked(UIButton sender) { var ssid = TxtSsid.Text.Trim(); var password = TxtPassword.Text.Trim(); if (string.IsNullOrWhiteSpace(ssid)) { var alert = new UIAlertController { Title = "No SSID set", Message = "You need do specify an SSID" }; alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } var config = new NEHotspotConfiguration(ssid, password, isWep: false); // See: https://developer.apple.com/documentation/networkextension/nehotspotconfiguration/2887518-joinonce config.JoinOnce = false; var tcs = new TaskCompletionSource <NSError>(); NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err)); var error = await tcs.Task; if (error != null) { var alert = new UIAlertController { Title = "Error", Message = error.Description }; alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } }
public void Connect(Models.WifiDescriptor descriptor, string passPhrase) { NEHotspotConfiguration wifiConfig = new NEHotspotConfiguration(descriptor.Ssid, passPhrase, false); wifiConfig.JoinOnce = true; try { if (this._wifiManager == null) { throw new WifiException("WifiConnector can not access the device WifiManager"); } this._wifiManager.RemoveConfiguration(descriptor.Ssid); this._wifiManager.ApplyConfiguration(wifiConfig, error => this.CompletionHandler(error, descriptor.Ssid)); } catch (Exception ex) { throw new WifiException("WifiConnector can not add the new wifi network configuration", ex); } }
private async void ConnectToWifi() { try { var config = new NEHotspotConfiguration("THETAYL02102089.OSC", "02102089", false) { JoinOnce = true }; var configManager = new NEHotspotConfigurationManager(); await configManager.ApplyConfigurationAsync(config); Console.WriteLine("Connected"); } catch (Foundation.NSErrorException error) { var kek = error; } catch (Exception e) { var kek = e; } }
public bool ConnectToWifi(string ssid, string password) { try { System.Diagnostics.Debug.WriteLine("connecting to network " + ssid); var wifiConfig = new NEHotspotConfiguration(ssid, password, false); wifiConfig.JoinOnce = true; var wifiManager = new NEHotspotConfigurationManager(); wifiManager.ApplyConfiguration(wifiConfig, (error) => { if (error != null) { System.Diagnostics.Debug.WriteLine("error while connecting to network " + ssid + ", error: " + error); } }); return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("connection error, ex=" + ex); return(false); } }