using System; namespace Shared.Net { public class WifiUtil { public void ConnectToWifi(Action action, string wifiName, string wifiPwd = null) { var hotspotConfig = new NetworkExtension.NEHotspotConfiguration(wifiName, wifiPwd, false); NetworkExtension.NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(hotspotConfig, (obj) => { if (action != null) { if (obj == null||obj.ToString().Contains("already associated")) { action(true); } else { action(false); } } }); } // 单例 static WifiUtil ourInstance = new WifiUtil(); public static WifiUtil Instance { get { return ourInstance; } } } }