update: 重构 FirebaseUtils, CodeReview
Signed-off-by: huyufei <yufei.hu@castbox.fm>
parent
23c1b8f4fc
commit
3f0f13be6c
|
|
@ -25,7 +25,7 @@ namespace Guru
|
||||||
private const string VALUE_ONLY_FOR_IOS = "idfa_only_for_ios";
|
private const string VALUE_ONLY_FOR_IOS = "idfa_only_for_ios";
|
||||||
|
|
||||||
public static bool IsDebug { get; set; } = false;
|
public static bool IsDebug { get; set; } = false;
|
||||||
private static bool _isGuruAnalyticInitOnce = false;
|
private static readonly bool _isGuruAnalyticInitOnce = false;
|
||||||
|
|
||||||
public static void InitGuruAnalyticService(GuruAnalyticsInitConfig initConfig, string firebaseId)
|
public static void InitGuruAnalyticService(GuruAnalyticsInitConfig initConfig, string firebaseId)
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Guru
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
IsDebug = true;
|
IsDebug = true;
|
||||||
#else
|
#else
|
||||||
IsDebug = isDebug;
|
IsDebug = initConfig.isDebug;
|
||||||
#endif
|
#endif
|
||||||
string appId = IPMConfig.IPM_X_APP_ID;
|
string appId = IPMConfig.IPM_X_APP_ID;
|
||||||
string deviceInfo = new DeviceInfoData().ToString();
|
string deviceInfo = new DeviceInfoData().ToString();
|
||||||
|
|
@ -54,8 +54,8 @@ namespace Guru
|
||||||
if(!string.IsNullOrEmpty(firebaseId))
|
if(!string.IsNullOrEmpty(firebaseId))
|
||||||
GuruAnalytics.Instance.SetFirebaseId(firebaseId); // 在自打点初始化之前, 需要调用一下设置 FirebaseId
|
GuruAnalytics.Instance.SetFirebaseId(firebaseId); // 在自打点初始化之前, 需要调用一下设置 FirebaseId
|
||||||
|
|
||||||
GuruAnalytics.Init(appId, deviceInfo, initConfig); // Android 初始化
|
GuruAnalytics.Init(appId, deviceInfo, initConfig, OnGuruAnalyticsInitComplete); // Android 初始化
|
||||||
UpdateAllValues();
|
UpdateAllUserProperties();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -245,9 +245,9 @@ namespace Guru
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取全部ID
|
/// 上报中台打点的用户属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void UpdateAllValues()
|
private static void UpdateAllUserProperties()
|
||||||
{
|
{
|
||||||
|
|
||||||
Debug.Log($"{TAG} --- UpdateAllValues");
|
Debug.Log($"{TAG} --- UpdateAllValues");
|
||||||
|
|
@ -296,7 +296,7 @@ namespace Guru
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GuruAnalytics.Instance.SetUserProperty(key, value);
|
GuruAnalytics.Instance.SetUserProperty(key, value);
|
||||||
UpdateAllValues(); // 同步所有的ID
|
UpdateAllUserProperties(); // 同步所有的ID
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -312,32 +312,6 @@ namespace Guru
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 自定义事件打点
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key"></param>
|
|
||||||
/// <param name="data"></param>
|
|
||||||
private static void TrackEventGuru(string key, Dictionary<string, dynamic> data = null, int priority = -1)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (data == null) data = new Dictionary<string, dynamic>();
|
|
||||||
GuruAnalytics.Instance.LogEvent(key, data, priority);
|
|
||||||
UpdateAllValues(); // 同步所有的ID
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
if (IsFirebaseReady)
|
|
||||||
{
|
|
||||||
Crashlytics.LogException(e);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogWarning(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置太极02阀值
|
/// 设置太极02阀值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,8 @@ namespace Guru
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (eventSetting == null) eventSetting = DefaultEventSetting;
|
if (eventSetting == null) eventSetting = DefaultEventSetting;
|
||||||
|
|
||||||
var dataStr = "";
|
var dataStr = "";
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@ using UnityEngine;
|
||||||
|
|
||||||
public static class NetworkUtil
|
public static class NetworkUtil
|
||||||
{
|
{
|
||||||
public static bool IsNetAvaliable => Application.internetReachability != NetworkReachability.NotReachable;
|
public static bool IsNetAvailable => Application.internetReachability != NetworkReachability.NotReachable;
|
||||||
}
|
}
|
||||||
|
|
@ -13,8 +13,6 @@ namespace Guru
|
||||||
|
|
||||||
private const float LOGIN_RETRY_MAX_TIME = 60; // 最大请求间隔时间
|
private const float LOGIN_RETRY_MAX_TIME = 60; // 最大请求间隔时间
|
||||||
private const float LOGIN_RETRY_INTERVAL = 10; // 最大请求间隔时间
|
private const float LOGIN_RETRY_INTERVAL = 10; // 最大请求间隔时间
|
||||||
|
|
||||||
|
|
||||||
private static float _retryDelayTime = 10; // 登录重试时间
|
private static float _retryDelayTime = 10; // 登录重试时间
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -36,8 +34,13 @@ namespace Guru
|
||||||
if (string.IsNullOrEmpty(authToken)) authToken = IPMConfig.IPM_FIREBASE_TOKEN;
|
if (string.IsNullOrEmpty(authToken)) authToken = IPMConfig.IPM_FIREBASE_TOKEN;
|
||||||
Log.I(LOG_TAG, $"[Auth] Firebase Token:{authToken}");
|
Log.I(LOG_TAG, $"[Auth] Firebase Token:{authToken}");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(authToken) || !NetworkUtil.IsNetAvaliable)
|
if (!string.IsNullOrEmpty(authToken) && NetworkUtil.IsNetAvailable)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
LoginFirebase(authToken, autoRetry, onLoginResult);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Token 为空 或 网络不可用
|
// Token 为空 或 网络不可用
|
||||||
if (autoRetry)
|
if (autoRetry)
|
||||||
{
|
{
|
||||||
|
|
@ -50,9 +53,10 @@ namespace Guru
|
||||||
// 不再重试
|
// 不再重试
|
||||||
onLoginResult?.Invoke(false);
|
onLoginResult?.Invoke(false);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void LoginFirebase(string authToken = "", bool autoRetry = true, Action<bool> onLoginResult = null)
|
||||||
|
{
|
||||||
FirebaseAuth.DefaultInstance.SignInWithCustomTokenAsync(authToken)
|
FirebaseAuth.DefaultInstance.SignInWithCustomTokenAsync(authToken)
|
||||||
.ContinueWithOnMainThread(task =>
|
.ContinueWithOnMainThread(task =>
|
||||||
{
|
{
|
||||||
|
|
@ -78,6 +82,7 @@ namespace Guru
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO:P0 协程不应该用在此场景
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 延迟调用 Firebase 登录请求
|
/// 延迟调用 Firebase 登录请求
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Guru
|
||||||
|
|
||||||
private static void UploadDeviceInfo()
|
private static void UploadDeviceInfo()
|
||||||
{
|
{
|
||||||
if (!NetworkUtil.IsNetAvaliable)
|
if (!NetworkUtil.IsNetAvailable)
|
||||||
{
|
{
|
||||||
double retryDelay = Math.Pow(2, _messageRetry);
|
double retryDelay = Math.Pow(2, _messageRetry);
|
||||||
_messageRetry++;
|
_messageRetry++;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue