using System; using Foundation; namespace Shared { public static class WiimuUPnP { /// /// 获取当前WIFI的名称 /// /// The ssid. public static string SSID { get { string[] supportedInterface; SystemConfiguration.CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterface); foreach (var s in supportedInterface) { NSDictionary nSDictionary; SystemConfiguration.CaptiveNetwork.TryCopyCurrentNetworkInfo(s, out nSDictionary); if (nSDictionary != null) { return nSDictionary.ValueForKey(SystemConfiguration.CaptiveNetwork.NetworkInfoKeySSID).ToString(); } } return null; } } static Action currentAction; /// /// 启动配置无线上网 /// /// The start. /// 密码 /// 配置完成后反馈的结果 public static void Start(string password,Action action) { if (SSID == null) { return; } Stop(); dateTime = DateTime.Now; currentAction = action; Shared.WiimuSmartlink.SharedInstance.StartProvision(SSID, password, (obj) => { if(action!=null){ action(obj); Stop(); } }); } static WiimuUPnP() { //定时检查 System.Threading.Tasks.Task.Run(() => { while (true) { System.Threading.Thread.Sleep(1000); if (30 <= (System.DateTime.Now - dateTime).TotalSeconds) { Stop(); if (currentAction != null) { currentAction("TimeOut"); } } } }); } /// /// 记录开始时间 /// static DateTime dateTime = DateTime.MaxValue; /// /// 停止配置无线上网 /// public static void Stop() { dateTime = DateTime.MaxValue; Shared.WiimuSmartlink.SharedInstance.StopProvision((obj) => { }); } } }