wxr
2020-03-05 0bdc0a135dbe31761b53f432ed34f347f0a4e36b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using Foundation;
 
namespace Shared
{
    
 
    public static class WiimuUPnP
    {
        /// <summary>
        /// 获取当前WIFI的名称
        /// </summary>
        /// <value>The ssid.</value>
        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<string> currentAction;
        /// <summary>
        /// 启动配置无线上网
        /// </summary>
        /// <returns>The start.</returns>
        /// <param name="password">密码</param>
        /// <param name="a">配置完成后反馈的结果</param>
        public static void Start(string password,Action<string> 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");
                        }
                    }
                }
            });
        }
 
        /// <summary>
        /// 记录开始时间
        /// </summary>
        static DateTime dateTime = DateTime.MaxValue;
 
        /// <summary>
        /// 停止配置无线上网
        /// </summary>
        public static void Stop()
        {
            dateTime = DateTime.MaxValue;
            Shared.WiimuSmartlink.SharedInstance.StopProvision((obj) => { });
        }
    }
}