From f23ad1b3f9f6193f35f72104d690b21dc67d5c1f Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 06 七月 2020 12:35:25 +0800 Subject: [PATCH] 去掉了访问外网的异步 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs | 141 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 134 insertions(+), 7 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs index 046b3fa..7bf85cc 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs @@ -40,7 +40,24 @@ { string myId = this.SSID; - if (myId.StartsWith("hdlZigbeeGW") == true) + if (myId != null && myId.StartsWith("hdlZigbeeGW") == true) + { + return true; + } + return false; + } + } + + /// <summary> + /// 褰撳墠鏄惁鏄疢ini缃戝叧鐑偣 + /// </summary> + public bool IsMiniGatewayHotspot + { + get + { + string myId = this.SSID; + + if (myId != null && myId.StartsWith("hdlZigbeeGW-") == true) { return true; } @@ -56,7 +73,12 @@ get { #if iOS - return string.Empty; + string ssiD = Shared.WiimuUPnP.SSID; + if (string.IsNullOrEmpty(ssiD) == false && ssiD.StartsWith("\"") && ssiD.EndsWith("\"")) + { + ssiD = ssiD.Substring(1, ssiD.Length - 2); + } + return ssiD; #endif #if Android string ssiD = null; @@ -92,7 +114,6 @@ /// </summary> private Com.Mediatek.Elian.ElianNative hdlWiFi = null; #endif - /// <summary> /// TCP鍗忚 /// </summary> @@ -105,6 +126,40 @@ /// Ap妯″紡缃戝叧杩斿洖鐨勭閽� /// </summary> private string randDesKey = null; + /// <summary> + /// 鏄惁宸茬粡娣诲姞缃戠粶鍙樺寲鐩戝惉 + /// </summary> + private bool hadAddListenNetWork = false; + + /// <summary> + /// 鑳藉惁璁块棶http + /// </summary> + private bool m_CanAccessHttp = true; + /// <summary> + /// 涓婁竴娆¤闂甴ttp鐨勬椂闂� + /// </summary> + private DateTime oldAccessHttpTime = DateTime.Now; + /// <summary> + /// 鑳藉惁璁块棶http + /// </summary> + public bool CanAccessHttp + { + set + { + m_CanAccessHttp = value; + oldAccessHttpTime = DateTime.Now; + } + get + { + //10绉掑悗鍏佽鍐嶆璁块棶 + if (m_CanAccessHttp == true || (DateTime.Now - oldAccessHttpTime).TotalMilliseconds > 10 * 1000) + { + oldAccessHttpTime = DateTime.Now; + return true; + } + return false; + } + } #endregion @@ -264,6 +319,77 @@ #endregion + #region 鈻� 鐩戝惉缃戠粶鍙樺寲_______________________ + + /// <summary> + /// 寮�鍚洃鍚綉缁� + /// </summary> + public void StartListenNetWork() + { + if (hadAddListenNetWork == true) + { + return; + } + hadAddListenNetWork = true; + +#if Android + //寮�鍚洃鍚畨鍗撶綉缁滃彉鍖� + BaseActivity.NetworkStateChanged += (value) => + { + //缃戠粶鍙樺寲 + this.NetworkStateChanged(value); + }; +#endif + +#if iOS + //寮�鍚洃鍚琁OS缃戠粶鍙樺寲 + GateWay.Ios.Reachability.ReachabilityChanged += (sender, e) => + { + var internetStatus = GateWay.Ios.Reachability.InternetConnectionStatus(); + if (internetStatus == GateWay.Ios.NetworkStatus.NotReachable)//娌℃湁缃戠粶杩炴帴 0 + { + //缃戠粶鍙樺寲 + this.NetworkStateChanged(0); + } + else if (internetStatus == GateWay.Ios.NetworkStatus.ReachableViaCarrierDataNetwork)//3,4G鐨勭綉缁滆繛鎺� 1 + { + //缃戠粶鍙樺寲 + this.NetworkStateChanged(1); + } + else if (internetStatus == GateWay.Ios.NetworkStatus.ReachableViaWiFiNetwork) //wifi鐨勭綉缁滆繛鎺� 2 + { + //缃戠粶鍙樺寲 + this.NetworkStateChanged(2); + } + }; +#endif + } + + /// <summary> + /// 鐩戝惉瀹夊崜缃戠粶鍙樺寲 + /// </summary> + /// <param name="value"></param> + private void NetworkStateChanged(int value) + { + //娌℃湁缃戠粶 + if (value == 0) + { + this.CanAccessHttp = false; + } + //鍙互鍙�4G + else if (value == 1) + { + this.CanAccessHttp = true; + } + //WIFI + else if (value == 2) + { + this.CanAccessHttp = true; + } + } + + #endregion + #region 鈻� 涓�鑸柟娉昣__________________________ #if Android @@ -278,10 +404,10 @@ { if (hdlWiFi == null) { - Com.Mediatek.Elian.ElianNative.LoadLib(); + var result2 = Com.Mediatek.Elian.ElianNative.LoadLib(); //鍒濆鍖朩i-Fi閰嶇綉 this.hdlWiFi = new Com.Mediatek.Elian.ElianNative(); - var value = hdlWiFi.InitSmartConnection(null, 1, 0); + var value = hdlWiFi.InitSmartConnection(null, 1, 1); } //寮�濮媁i-Fi閰嶇綉 var result = hdlWiFi.StartSmartConnection(wifiName, wifiPsw, p2); @@ -297,6 +423,7 @@ { //鍋滄Wi-Fi閰嶇綉 var result = hdlWiFi.StopSmartConnection(); + hdlWiFi = null; } } #endif @@ -308,10 +435,10 @@ /// <param name="wifiPsw">wifi瀵嗙爜</param> /// <param name="p2">鎴戜篃涓嶇煡閬撹繖涓槸浠�涔堜笢瑗�</param> /// <returns></returns> - public bool StartSmartConnection(string wifiName, string wifiPsw, string p2 = "1") + public bool StartSmartConnection(string wifiName, string wifiPsw, string p2 = "") { //鍒濆鍖朩i-Fi杩炴帴 - Com.Mediatek.Elian.ElianNative.InitSmartConnection(null, 1, 1); + Com.Mediatek.Elian.ElianNative.InitSmartConnection("1", 1, 1); //寮�濮媁i-Fi杩炴帴 var result = Com.Mediatek.Elian.ElianNative.StartSmartConnection(wifiName, wifiPsw, p2); return true; -- Gitblit v1.8.0