From 742d81eab84cb5afdf4a2f0bb092bfc89a5dccef Mon Sep 17 00:00:00 2001 From: huyufei Date: Tue, 30 Jul 2024 22:53:48 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=20NetworkStatusMonitor=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84=E5=92=8C=20Review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1020899 --user=yufei.hu 【BI】guru 埋点增加网络相关用户属性 https://www.tapd.cn/58098289/s/1160727 Signed-off-by: huyufei --- .../GuruCore/Runtime/Analytics/Analytics.cs | 2 +- .../Runtime/NetworkStatusMonitor.cs | 91 ++----------------- 2 files changed, 7 insertions(+), 86 deletions(-) diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs index d9ddfe0..143c39f 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs @@ -162,7 +162,7 @@ namespace Guru } /// - /// Firebase上报用户属性 + /// 设置用户属性 /// public static void SetUserProperty(string key, string value) { diff --git a/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs b/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs index b2236b9..96353bd 100644 --- a/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs +++ b/Runtime/GuruNetworkMonitor/Runtime/NetworkStatusMonitor.cs @@ -1,10 +1,8 @@ namespace Guru.Network { - + using Guru; using System; - using System.Collections.Generic; - using System.Linq; using UnityEngine; public class NetworkStatusMonitor @@ -19,98 +17,21 @@ namespace Guru.Network private const string NETWORK_STATUS_BLUETOOTH = "bluetooth"; private const string NETWORK_STATUS_OTHER = "other"; - private bool _isReady = false; - - private INetworkStatusProxy _proxy; - private INetworkStatusProxy Proxy - { - get - { - if (_proxy == null) - { -#if UNITY_EDITOR - _proxy = new NetworkStatusEditor(); -#elif UNITY_ANDROID - _proxy = new NetworkStatusAndroid(); -#elif UNITY_IOS - _proxy = new NetworkStatusIOS(); -#endif - } - - if (_proxy == null) - { - // 如果未实现则报异常 - throw new NotImplementedException("Can't find NetworkStatusProxy instance!!"); - } - - return _proxy; - } - - } - - /// - /// 网络状态列表 - /// - private List _statusNameList = new List() - { - NETWORK_STATUS_VPN, - NETWORK_STATUS_TETHER, - NETWORK_STATUS_MOBILE, - NETWORK_STATUS_WIFI, - NETWORK_STATUS_ETHERNET, - NETWORK_STATUS_BLUETOOTH, - NETWORK_STATUS_OTHER, - NETWORK_STATUS_NONE, - }; - - public void Init(Action onInitComplete = null) - { - Proxy.Init(success => - { - _isReady = success; - onInitComplete?.Invoke(success); - }); - } - /// /// 获取网络状态 /// /// public string GetNetworkStatus() { - if (_isReady) + switch (Application.internetReachability) { - var status = Proxy.GetNetworkStatus(); - if (status != null && status.Length > 0) - { - string statusName = ""; - for (int i = 0; i < _statusNameList.Count; i++) - { - // 根据名称优先级, 先获取到的优先上报 - statusName = _statusNameList[i]; - if (status.Contains(statusName)) - { - Debug.Log($"{Tag} --- GetNetworkStatus: [{string.Join(",", status)}]"); - return statusName; - } - } - } + case NetworkReachability.ReachableViaLocalAreaNetwork: + return NETWORK_STATUS_WIFI; + case NetworkReachability.ReachableViaCarrierDataNetwork: + return NETWORK_STATUS_MOBILE; } - Debug.LogWarning($"{Tag} --- Network Monitor is not ready!"); return NETWORK_STATUS_NONE; } - - // private void OnProxyInitComplete(bool success) - // { - // if (success) - // { - // Debug.Log($"{Tag} --- NetworkStatusMonitor init success"); - // } - // else - // { - // Debug.LogError($"{Tag} --- NetworkStatusMonitor init failed"); - // } - // } } } \ No newline at end of file