wxr
2020-07-06 23c075a9c27946773feccf05abc90489a6bf5203
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
using System;
namespace Shared.Net
{
    public  class WifiUtil
    {
        public  void ConnectToWifi(Action<bool> 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;
            }
        }
    }
}