2023-12-26 03:40:48 +00:00
|
|
|
namespace Guru
|
|
|
|
|
{
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System;
|
2023-12-28 08:33:12 +00:00
|
|
|
using System.Collections;
|
2023-12-27 12:24:16 +00:00
|
|
|
using System.Collections.Generic;
|
2024-05-07 12:37:57 +00:00
|
|
|
using Debug = UnityEngine.Debug;
|
2024-07-26 03:08:31 +00:00
|
|
|
using Guru.Network;
|
2024-08-11 07:35:43 +00:00
|
|
|
using System.Linq;
|
2023-12-26 03:40:48 +00:00
|
|
|
|
|
|
|
|
public partial class GuruSDK: MonoBehaviour
|
|
|
|
|
{
|
2024-06-21 06:39:55 +00:00
|
|
|
// SDK_VERSION
|
2024-07-25 02:17:16 +00:00
|
|
|
public const string Version = "1.1.0";
|
2024-05-31 05:41:13 +00:00
|
|
|
|
2024-06-21 06:39:55 +00:00
|
|
|
// Const
|
2024-07-31 04:56:01 +00:00
|
|
|
private const string Tag = "[Guru]";
|
2023-12-27 12:24:16 +00:00
|
|
|
public const string ServicesConfigKey = "guru_services";
|
2023-12-26 03:40:48 +00:00
|
|
|
|
|
|
|
|
private static GuruSDK _instance;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 单利引用
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static GuruSDK Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if(null == _instance)
|
|
|
|
|
{
|
|
|
|
|
_instance = CreateInstance();
|
|
|
|
|
}
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private GuruSDKInitConfig _initConfig;
|
|
|
|
|
|
2024-07-31 04:56:01 +00:00
|
|
|
private static GuruSDKInitConfig InitConfig => Instance._initConfig;
|
|
|
|
|
private static GuruSDKModel Model => GuruSDKModel.Instance;
|
2023-12-27 12:24:16 +00:00
|
|
|
private static GuruServicesConfig _appServicesConfig;
|
2024-01-10 11:16:10 +00:00
|
|
|
private static GuruSettings _guruSettings;
|
|
|
|
|
private static GuruSettings GuruSettings
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_guruSettings == null) _guruSettings = GuruSettings.Instance;
|
|
|
|
|
return _guruSettings;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-14 03:52:14 +00:00
|
|
|
|
2024-03-06 04:36:41 +00:00
|
|
|
private static DateTime _initTime;
|
2024-01-17 12:46:23 +00:00
|
|
|
private static bool _isDebugEnabled = false;
|
2023-12-26 03:40:48 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Debug Mode
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsDebugMode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR || DEBUG
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
2024-01-17 12:46:23 +00:00
|
|
|
return _isDebugEnabled;
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-01-07 14:59:02 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化成功标志位
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsInitialSuccess { get; private set; } = false;
|
2024-03-22 05:20:54 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Firebase 就绪标志位
|
|
|
|
|
/// </summary>
|
2024-03-20 06:29:43 +00:00
|
|
|
public static bool IsFirebaseReady { get; private set; } = false;
|
2024-03-22 05:20:54 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// 服务就绪标志位
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsServiceReady { get; private set; } = false;
|
2024-03-20 06:29:43 +00:00
|
|
|
|
2024-08-15 05:53:44 +00:00
|
|
|
private Firebase.Auth.FirebaseUser _firebaseUser;
|
|
|
|
|
[Obsolete("获取 FirebaseUser 的属性接口即将废弃,请改用 <GuruSDK.Callbacks.SDK.OnFirebaseUserAuthResult += OnMyGetFirebaseUserCallback> 来异步获取该属性")]
|
|
|
|
|
public static Firebase.Auth.FirebaseUser FirebaseUser => Instance?._firebaseUser ?? null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
#region 初始化
|
2023-12-27 12:24:16 +00:00
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
private static GuruSDK CreateInstance()
|
|
|
|
|
{
|
|
|
|
|
var go = new GameObject(nameof(GuruSDK));
|
|
|
|
|
DontDestroyOnLoad(go);
|
|
|
|
|
_instance = go.AddComponent<GuruSDK>();
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
2024-07-30 12:31:41 +00:00
|
|
|
|
|
|
|
|
// TODO : 下个版本需要将 整个 GuruSDK 做功能性的拆分
|
2024-07-31 12:59:36 +00:00
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
public static void Init(Action<bool> onComplete)
|
|
|
|
|
{
|
2024-08-02 03:40:05 +00:00
|
|
|
Init(GuruSDKInitConfig.Builder().Build(), onComplete);
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Init(GuruSDKInitConfig config, Action<bool> onComplete)
|
|
|
|
|
{
|
2024-08-11 09:16:35 +00:00
|
|
|
_initTime = DateTime.UtcNow;
|
2024-05-11 02:28:58 +00:00
|
|
|
// ----- First Open Time -----
|
2024-05-28 03:34:25 +00:00
|
|
|
// SetFirstOpenTime(GetFirstOpenTime()); // FirstOpenTime
|
2024-07-31 04:56:01 +00:00
|
|
|
LogI($"#1 ---- Guru SDK [{Version}] ----\n{config}");
|
2023-12-26 03:40:48 +00:00
|
|
|
Instance.StartWithConfig(config, onComplete);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动SDK
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="config"></param>
|
|
|
|
|
/// <param name="onComplete"></param>
|
|
|
|
|
private void StartWithConfig(GuruSDKInitConfig config, Action<bool> onComplete)
|
|
|
|
|
{
|
2024-01-17 12:46:23 +00:00
|
|
|
IsInitialSuccess = false;
|
2023-12-26 03:40:48 +00:00
|
|
|
_initConfig = config;
|
2024-01-17 12:46:23 +00:00
|
|
|
_isDebugEnabled = config.DebugMode;
|
2024-04-09 08:58:08 +00:00
|
|
|
|
2024-07-25 15:00:22 +00:00
|
|
|
if (config.EnableDebugLogEvent) Analytics.EnableDebugAnalytics = true; // 允许 Debug 模式下打点
|
2024-07-26 03:53:21 +00:00
|
|
|
if (!config.AutoNotificationPermission) FirebaseUtil.SetAutoFetchFcmToken(false); // 不允许自动启动获取 FCM Token
|
2024-07-25 15:00:22 +00:00
|
|
|
|
2024-04-09 09:24:41 +00:00
|
|
|
InitUpdaters(); // Updaters
|
2024-04-09 08:58:08 +00:00
|
|
|
InitThreadHandler(); // 初始化线程处理器
|
2024-07-31 04:56:01 +00:00
|
|
|
InitServices(); // 初始化所有的服务
|
2024-07-26 03:08:31 +00:00
|
|
|
InitNetworkMonitor(); // 网络状态
|
|
|
|
|
|
2024-07-25 15:00:22 +00:00
|
|
|
onComplete?.Invoke(true);
|
2024-01-08 07:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-25 15:00:22 +00:00
|
|
|
private void InitServices()
|
2024-01-08 07:01:04 +00:00
|
|
|
{
|
2024-08-07 16:01:10 +00:00
|
|
|
//---------- Start Analytics ------------
|
|
|
|
|
LogI($"#1.1 ---- Init Analytics ----");
|
|
|
|
|
// 初始化打点类
|
|
|
|
|
Analytics.Init();
|
|
|
|
|
// 从 Model 中注入打点属性初始值
|
2024-08-11 09:16:35 +00:00
|
|
|
Analytics.SetFirstOpenTime(IPMConfig.FIRST_OPEN_TIME);
|
2024-08-11 10:43:13 +00:00
|
|
|
Analytics.SetIsIapUser(Model.IsIapUser);
|
|
|
|
|
// Analytics.SetBLevel(Model.BLevel);
|
|
|
|
|
// Analytics.SetBPlay(Model.BPlay);
|
2024-08-07 16:01:10 +00:00
|
|
|
|
2024-04-09 08:58:08 +00:00
|
|
|
//---- Start All tools ----
|
2024-03-14 03:52:14 +00:00
|
|
|
LogI($"#2 --- InitFirebase ---");
|
2023-12-26 03:40:48 +00:00
|
|
|
//---------- Start Firebase ------------
|
2024-07-12 02:29:30 +00:00
|
|
|
StartFirebaseService();
|
2024-03-14 03:52:14 +00:00
|
|
|
LogI($"#2.1 --- InitFacebook ---");
|
2023-12-26 03:40:48 +00:00
|
|
|
//---------- Start Facebook ------------
|
2024-07-25 15:00:22 +00:00
|
|
|
FBService.Instance.StartService(Analytics.OnFBInitComplete);
|
2024-03-14 03:52:14 +00:00
|
|
|
|
2024-03-15 04:59:20 +00:00
|
|
|
IsInitialSuccess = true;
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
2024-07-25 15:00:22 +00:00
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// 注入云控参数基础数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-08-08 18:40:36 +00:00
|
|
|
private string LoadDefaultGuruServiceJson()
|
2023-12-27 12:24:16 +00:00
|
|
|
{
|
2024-08-08 18:40:36 +00:00
|
|
|
// 加载本地 Services 配置值
|
|
|
|
|
var txtAsset = Resources.Load<TextAsset>(ServicesConfigKey);
|
|
|
|
|
if (txtAsset != null)
|
|
|
|
|
{
|
|
|
|
|
return txtAsset.text;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 拉取云控参数完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="success"></param>
|
|
|
|
|
private void OnFetchRemoteCallback(bool success)
|
|
|
|
|
{
|
2024-03-14 03:52:14 +00:00
|
|
|
LogI($"#6 --- Remote fetch complete: {success} ---");
|
2023-12-27 12:24:16 +00:00
|
|
|
ABTestManager.Init(); // 启动AB测试解析器
|
2024-07-31 04:56:01 +00:00
|
|
|
Callbacks.Remote.InvokeOnRemoteFetchComplete(success);
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
2024-04-09 08:58:08 +00:00
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
UpdateAllUpdates(); // 驱动所有的更新器
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region App Remote Update
|
|
|
|
|
|
2024-03-11 10:51:49 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Apply Cloud guru-service configs for sdk assets
|
|
|
|
|
/// </summary>
|
2024-07-31 04:56:01 +00:00
|
|
|
private void InitAllGuruServices()
|
2023-12-27 12:24:16 +00:00
|
|
|
{
|
2024-06-20 10:30:22 +00:00
|
|
|
// -------- Init Analytics ---------
|
2024-06-18 02:24:43 +00:00
|
|
|
SetSDKEventPriority();
|
2024-07-31 04:56:01 +00:00
|
|
|
// -------- Init Notification -----------
|
2024-06-20 10:30:22 +00:00
|
|
|
InitNotiPermission();
|
2024-04-07 08:17:46 +00:00
|
|
|
|
2024-01-31 04:54:03 +00:00
|
|
|
bool useKeywords = false;
|
2024-03-18 02:22:11 +00:00
|
|
|
bool useIAP = _initConfig.IAPEnabled;
|
2024-03-01 05:13:26 +00:00
|
|
|
bool appleReview = false;
|
2024-07-31 04:56:01 +00:00
|
|
|
// bool enableAnaErrorLog = false;
|
2023-12-27 12:24:16 +00:00
|
|
|
|
2024-04-03 04:47:25 +00:00
|
|
|
//----------- Set GuruServices ----------------
|
2023-12-27 12:24:16 +00:00
|
|
|
var services = GetRemoteServicesConfig();
|
|
|
|
|
if (services != null)
|
|
|
|
|
{
|
|
|
|
|
_appServicesConfig = services;
|
2024-03-01 05:13:26 +00:00
|
|
|
useKeywords = _appServicesConfig.KeywordsEnabled();
|
2024-03-18 01:37:28 +00:00
|
|
|
// 使用初始化配置中的 IAPEnable来联合限定, 如果本地写死关闭则不走云控开启
|
|
|
|
|
useIAP = _initConfig.IAPEnabled && _appServicesConfig.IsIAPEnabled();
|
2024-07-31 04:56:01 +00:00
|
|
|
// enableAnaErrorLog = _appServicesConfig.EnableAnaErrorLog();
|
2024-01-31 04:54:03 +00:00
|
|
|
|
2024-03-08 09:05:36 +00:00
|
|
|
Try(() =>
|
2024-01-08 10:45:22 +00:00
|
|
|
{
|
2024-04-09 08:58:08 +00:00
|
|
|
LogI($"#4.1 --- Start apply services ---");
|
2024-03-14 03:52:14 +00:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// 自打点设置错误上报
|
2024-07-25 15:00:22 +00:00
|
|
|
// if(enableAnaErrorLog) GuruAnalytics.EnableErrorLog = true;
|
2024-03-08 09:05:36 +00:00
|
|
|
|
2024-03-14 03:52:14 +00:00
|
|
|
// adjust 事件设置
|
2024-03-08 09:05:36 +00:00
|
|
|
if (null != _appServicesConfig.adjust_settings && null != GuruSettings)
|
2024-01-10 06:02:53 +00:00
|
|
|
{
|
2024-03-08 09:05:36 +00:00
|
|
|
// 更新 Adjust Tokens
|
|
|
|
|
GuruSettings.UpdateAdjustTokens(
|
|
|
|
|
_appServicesConfig.adjust_settings.AndroidToken(),
|
|
|
|
|
_appServicesConfig.adjust_settings.iOSToken());
|
|
|
|
|
// 更新 Adjust Events
|
|
|
|
|
GuruSettings.UpdateAdjustEvents(_appServicesConfig.adjust_settings.events);
|
2024-01-10 06:02:53 +00:00
|
|
|
}
|
2024-03-08 09:05:36 +00:00
|
|
|
|
2024-07-31 04:56:01 +00:00
|
|
|
LogI($"#4.2 --- Start GuruSettings ---");
|
2024-03-14 03:52:14 +00:00
|
|
|
// GuruSettings 设置
|
2024-03-08 09:05:36 +00:00
|
|
|
if (null != _appServicesConfig.app_settings)
|
2024-01-31 04:54:03 +00:00
|
|
|
{
|
2024-03-08 09:05:36 +00:00
|
|
|
if (_appServicesConfig.Tch02Value() > 0)
|
|
|
|
|
{
|
|
|
|
|
Analytics.EnableTch02Event = true;
|
|
|
|
|
Analytics.SetTch02TargetValue(_appServicesConfig.Tch02Value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置获取设备 UUID 的方法
|
|
|
|
|
if (_appServicesConfig.UseUUID())
|
|
|
|
|
{
|
|
|
|
|
IPMConfig.UsingUUID = true; // 开始使用 UUID 作为 DeviceID 标识
|
|
|
|
|
}
|
2024-01-31 04:54:03 +00:00
|
|
|
|
2024-03-08 11:27:55 +00:00
|
|
|
#if UNITY_IOS
|
|
|
|
|
// 苹果审核标志位
|
|
|
|
|
appleReview = _appServicesConfig.IsAppReview();
|
2024-03-01 05:13:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
2024-03-08 09:05:36 +00:00
|
|
|
if (null != GuruSettings)
|
|
|
|
|
{
|
|
|
|
|
// 更新和升级 GuruSettings 对应的值
|
|
|
|
|
GuruSettings.UpdateAppSettings(
|
|
|
|
|
_appServicesConfig.app_settings.bundle_id,
|
|
|
|
|
_appServicesConfig.fb_settings?.fb_app_id ?? "",
|
|
|
|
|
_appServicesConfig.app_settings.support_email,
|
|
|
|
|
_appServicesConfig.app_settings.privacy_url,
|
|
|
|
|
_appServicesConfig.app_settings.terms_url,
|
|
|
|
|
_appServicesConfig.app_settings.android_store,
|
2024-05-11 03:34:51 +00:00
|
|
|
_appServicesConfig.app_settings.ios_store,
|
2024-05-31 08:19:20 +00:00
|
|
|
_appServicesConfig.parameters?.using_uuid ?? false,
|
|
|
|
|
_appServicesConfig.parameters?.cdn_host ?? "");
|
2024-05-07 12:37:57 +00:00
|
|
|
|
|
|
|
|
_appBundleId = _appServicesConfig.app_settings.bundle_id; // 配置预设的 BundleId
|
2024-03-08 09:05:36 +00:00
|
|
|
}
|
2024-01-31 04:54:03 +00:00
|
|
|
}
|
2024-03-08 09:05:36 +00:00
|
|
|
//---------------------------------
|
|
|
|
|
}, ex =>
|
|
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogError($"--- ERROR on apply services: {ex.Message}");
|
2024-03-08 09:05:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
2024-04-03 04:47:25 +00:00
|
|
|
//----------- Set IAP ----------------
|
2024-05-22 13:30:05 +00:00
|
|
|
if (useIAP)
|
|
|
|
|
{
|
|
|
|
|
// InitIAP(_initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP
|
|
|
|
|
Try(() =>
|
|
|
|
|
{
|
|
|
|
|
LogI($"#4.3 --- Start IAP ---");
|
|
|
|
|
if (_initConfig.GoogleKeys == null || _initConfig.AppleRootCerts == null)
|
|
|
|
|
{
|
2024-08-11 07:03:13 +00:00
|
|
|
LogEx("[IAP] GoogleKeys is null when using IAPService! Integration failed. App will Exit");
|
2024-05-22 13:30:05 +00:00
|
|
|
}
|
2024-08-15 05:53:44 +00:00
|
|
|
|
2024-05-22 13:30:05 +00:00
|
|
|
InitIAP(UID, _initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP
|
|
|
|
|
}, ex =>
|
|
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogError($"--- ERROR on useIAP: {ex.Message}");
|
2024-05-22 13:30:05 +00:00
|
|
|
});
|
|
|
|
|
}
|
2024-04-03 04:47:25 +00:00
|
|
|
//----------- Set Keywords ----------------
|
2024-01-31 04:54:03 +00:00
|
|
|
if (useKeywords)
|
|
|
|
|
{
|
2024-04-02 07:27:34 +00:00
|
|
|
// KeywordsManager.Install(Model.IsIAPUser, Model.SuccessLevelId); // 启动Keyword管理器
|
2024-03-08 09:05:36 +00:00
|
|
|
Try(() =>
|
|
|
|
|
{
|
2024-04-09 08:58:08 +00:00
|
|
|
LogI($"#4.4 --- Start Keywords ---");
|
2024-08-08 18:40:36 +00:00
|
|
|
KeywordsManager.Install(Model.IsIapUser, Model.BLevel); // 启动Keyword管理器
|
2024-03-08 09:05:36 +00:00
|
|
|
}, ex =>
|
|
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogError($"--- ERROR on Keywords: {ex.Message}");
|
2024-03-08 09:05:36 +00:00
|
|
|
});
|
2023-12-28 08:33:12 +00:00
|
|
|
}
|
2024-03-01 05:13:26 +00:00
|
|
|
|
|
|
|
|
#if UNITY_IOS
|
|
|
|
|
if (appleReview)
|
|
|
|
|
{
|
2024-03-08 09:05:36 +00:00
|
|
|
// StartAppleReviewFlow(); // 直接显示 ATT 弹窗, 跳过 Consent 流程
|
|
|
|
|
Try(() =>
|
2024-03-08 11:27:55 +00:00
|
|
|
{
|
2024-08-08 12:54:55 +00:00
|
|
|
LogI($"#4.5 --- StartAppleReviewFlow ---");
|
2024-03-08 11:27:55 +00:00
|
|
|
StartAppleReviewFlow(); // 直接显示 ATT 弹窗, 跳过 Consent 流程
|
|
|
|
|
}, ex =>
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError($"--- ERROR on StartAppleReviewFlow: {ex.Message}");
|
|
|
|
|
});
|
2024-03-01 05:13:26 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-04-03 04:47:25 +00:00
|
|
|
//----------- Set Consent ----------------
|
2024-03-01 05:13:26 +00:00
|
|
|
if (!InitConfig.UseCustomConsent && !appleReview)
|
|
|
|
|
{
|
2024-08-08 12:54:55 +00:00
|
|
|
LogI($"#4.6 --- Start Consent Flow ---");
|
2024-07-31 04:56:01 +00:00
|
|
|
Try(StartConsentFlow, ex =>
|
2024-03-08 09:05:36 +00:00
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogError($"--- ERROR on StartConsentFlow: {ex.Message}");
|
2024-03-08 09:05:36 +00:00
|
|
|
});
|
2024-03-01 05:13:26 +00:00
|
|
|
}
|
2024-03-22 05:20:54 +00:00
|
|
|
|
2024-05-07 12:37:57 +00:00
|
|
|
#if UNITY_ANDROID
|
2024-08-08 18:40:36 +00:00
|
|
|
LogI($"#5.1 --- Android StartAndroidDebug Cmd lines---");
|
2024-05-07 12:37:57 +00:00
|
|
|
// Android 命令行调试
|
|
|
|
|
StartAndroidDebugCmds();
|
|
|
|
|
#endif
|
2024-07-31 04:56:01 +00:00
|
|
|
|
2024-08-08 12:54:55 +00:00
|
|
|
IsServiceReady = true;
|
|
|
|
|
|
|
|
|
|
// 中台服务初始化结束
|
|
|
|
|
Callbacks.SDK.InvokeOnGuruServiceReady();
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
2024-05-22 13:30:05 +00:00
|
|
|
|
2024-03-11 10:51:49 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Get the guru-service cloud config value;
|
|
|
|
|
/// User can fetch the cloud guru-service config by using Custom Service Key
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-12-27 12:24:16 +00:00
|
|
|
private GuruServicesConfig GetRemoteServicesConfig()
|
|
|
|
|
{
|
2024-03-19 09:33:37 +00:00
|
|
|
|
|
|
|
|
string defaultJson = GetRemoteString(ServicesConfigKey);
|
|
|
|
|
|
|
|
|
|
bool useCustomKey = false;
|
2024-03-11 10:51:49 +00:00
|
|
|
string key = ServicesConfigKey;
|
|
|
|
|
if (!string.IsNullOrEmpty(_initConfig.CustomServiceKey))
|
|
|
|
|
{
|
|
|
|
|
key = _initConfig.CustomServiceKey;
|
2024-03-19 09:33:37 +00:00
|
|
|
useCustomKey = true;
|
2024-03-11 10:51:49 +00:00
|
|
|
}
|
2024-03-19 09:33:37 +00:00
|
|
|
var json = GetRemoteString(key); // Cloud cached data
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(json) && useCustomKey && !string.IsNullOrEmpty(defaultJson))
|
|
|
|
|
{
|
|
|
|
|
// No remote data fetched from cloud, should use default values
|
|
|
|
|
json = defaultJson;
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.Log($"{Tag} --- No remote data found with: {key} -> Using default key {ServicesConfigKey} and local data!!!");
|
2024-03-19 09:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
if (!string.IsNullOrEmpty(json))
|
|
|
|
|
{
|
|
|
|
|
return JsonParser.ToObject<GuruServicesConfig>(json);
|
|
|
|
|
}
|
2024-03-19 09:33:37 +00:00
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2024-03-08 09:05:36 +00:00
|
|
|
|
|
|
|
|
private void Try(Action method, Action<Exception> onException = null, Action onFinal = null)
|
|
|
|
|
{
|
|
|
|
|
if (method == null) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
method.Invoke();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-08-11 07:03:13 +00:00
|
|
|
LogEx(ex);
|
2024-03-08 09:05:36 +00:00
|
|
|
// ignored
|
|
|
|
|
onException?.Invoke(ex);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
// Finally
|
|
|
|
|
onFinal?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
#endregion
|
|
|
|
|
|
2024-03-01 05:13:26 +00:00
|
|
|
#region Apple 审核流程逻辑
|
|
|
|
|
|
|
|
|
|
#if UNITY_IOS
|
|
|
|
|
private void StartAppleReviewFlow()
|
|
|
|
|
{
|
|
|
|
|
CheckAttStatus();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2023-12-26 03:40:48 +00:00
|
|
|
#endregion
|
2023-12-27 12:24:16 +00:00
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
#region Logging
|
2024-08-08 18:40:36 +00:00
|
|
|
|
|
|
|
|
private static void LogI(object message)
|
2023-12-26 03:40:48 +00:00
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.Log($"{Tag} {message}");
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
2024-08-08 18:40:36 +00:00
|
|
|
|
|
|
|
|
private static void LogW(object message)
|
2023-12-26 03:40:48 +00:00
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogWarning($"{Tag} {message}");
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
2024-08-08 18:40:36 +00:00
|
|
|
|
|
|
|
|
private static void LogE(object message)
|
2023-12-26 03:40:48 +00:00
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogError($"{Tag} {message}");
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-08 18:40:36 +00:00
|
|
|
|
2024-08-11 07:03:13 +00:00
|
|
|
private static void LogEx(string message)
|
2023-12-27 12:24:16 +00:00
|
|
|
{
|
2024-08-11 07:03:13 +00:00
|
|
|
LogEx( new Exception($"{Tag} {message}"));
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
2024-08-08 18:40:36 +00:00
|
|
|
|
2024-08-11 07:03:13 +00:00
|
|
|
private static void LogEx(Exception e)
|
2023-12-27 12:24:16 +00:00
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
Debug.LogException(e);
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-04 13:10:25 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// 上报崩溃信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
public static void Report(string message)
|
|
|
|
|
{
|
2024-03-14 03:52:14 +00:00
|
|
|
Analytics.LogCrashlytics(message, false);
|
2024-02-04 13:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上报异常
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
public static void ReportException(string message)
|
|
|
|
|
{
|
2024-03-14 03:52:14 +00:00
|
|
|
Analytics.LogCrashlytics(message);
|
2024-02-04 13:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上报异常 Exception
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ex"></param>
|
|
|
|
|
public static void ReportException(Exception ex)
|
|
|
|
|
{
|
2024-03-14 03:52:14 +00:00
|
|
|
Analytics.LogCrashlytics(ex);
|
2024-02-04 13:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
#endregion
|
2023-12-27 12:24:16 +00:00
|
|
|
|
|
|
|
|
#region 生命周期
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 暂停时处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paused"></param>
|
|
|
|
|
private void OnAppPauseHandler(bool paused)
|
|
|
|
|
{
|
|
|
|
|
if(paused) Model.Save(true); // 强制保存数据
|
2024-07-31 04:56:01 +00:00
|
|
|
Callbacks.App.InvokeOnAppPaused(paused);
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
2023-12-26 03:40:48 +00:00
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
private void OnApplicationPause(bool paused)
|
|
|
|
|
{
|
|
|
|
|
OnAppPauseHandler(paused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnApplicationFocus(bool hasFocus)
|
|
|
|
|
{
|
|
|
|
|
OnAppPauseHandler(!hasFocus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnApplicationQuit()
|
|
|
|
|
{
|
|
|
|
|
Model.Save(true);
|
2024-07-31 04:56:01 +00:00
|
|
|
Callbacks.App.InvokeOnAppQuit();
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 延迟处理
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动协程
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="enumerator"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Coroutine DoCoroutine(IEnumerator enumerator)
|
|
|
|
|
{
|
|
|
|
|
return Instance != null ? Instance.StartCoroutine(enumerator) : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void KillCoroutine(Coroutine coroutine)
|
|
|
|
|
{
|
|
|
|
|
if(coroutine != null)
|
|
|
|
|
Instance.StopCoroutine(coroutine);
|
|
|
|
|
}
|
2024-01-10 10:22:02 +00:00
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// 延时执行
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="seconds"></param>
|
|
|
|
|
/// <param name="callback"></param>
|
2024-03-06 04:36:41 +00:00
|
|
|
public static Coroutine Delay(float seconds, Action callback)
|
2023-12-27 12:24:16 +00:00
|
|
|
{
|
2024-03-06 04:36:41 +00:00
|
|
|
return DoCoroutine(Instance.OnDelayCall(seconds, callback));
|
2023-12-27 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator OnDelayCall(float delay, Action callback)
|
|
|
|
|
{
|
|
|
|
|
if (delay > 0)
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(delay);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
callback?.Invoke();
|
|
|
|
|
}
|
2024-01-10 10:22:02 +00:00
|
|
|
|
2023-12-27 12:24:16 +00:00
|
|
|
#endregion
|
2024-04-09 08:58:08 +00:00
|
|
|
|
|
|
|
|
#region 帧更新 Updater
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<IUpdater> _updaterRunningList;
|
|
|
|
|
private List<IUpdater> _updaterRemoveList;
|
|
|
|
|
|
|
|
|
|
private void InitUpdaters()
|
|
|
|
|
{
|
|
|
|
|
_updaterRunningList = new List<IUpdater>(20);
|
|
|
|
|
_updaterRemoveList = new List<IUpdater>(20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAllUpdates()
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
// ---- Updater Trigger ----
|
|
|
|
|
if (_updaterRunningList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < _updaterRunningList.Count)
|
|
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
var updater = _updaterRunningList[i];
|
2024-04-09 08:58:08 +00:00
|
|
|
if (updater != null)
|
|
|
|
|
{
|
|
|
|
|
if (updater.State == UpdaterState.Running)
|
|
|
|
|
{
|
|
|
|
|
updater.OnUpdate();
|
|
|
|
|
}
|
|
|
|
|
else if(updater.State == UpdaterState.Kill)
|
|
|
|
|
{
|
|
|
|
|
_updaterRemoveList.Add(updater);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_updaterRunningList.RemoveAt(i);
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_updaterRemoveList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < _updaterRemoveList.Count)
|
|
|
|
|
{
|
|
|
|
|
RemoveUpdater(_updaterRemoveList[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
_updaterRemoveList.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 注册帧更新器
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="updater"></param>
|
|
|
|
|
public static void RegisterUpdater(IUpdater updater)
|
|
|
|
|
{
|
|
|
|
|
Instance.AddUpdater(updater);
|
|
|
|
|
updater.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void AddUpdater(IUpdater updater)
|
|
|
|
|
{
|
|
|
|
|
if (_updaterRunningList == null) _updaterRunningList = new List<IUpdater>(20);
|
|
|
|
|
_updaterRunningList.Add(updater);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveUpdater(IUpdater updater)
|
|
|
|
|
{
|
|
|
|
|
if (_updaterRunningList != null && updater != null)
|
|
|
|
|
{
|
|
|
|
|
_updaterRunningList.Remove(updater);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-05-07 12:37:57 +00:00
|
|
|
|
2024-07-25 02:17:16 +00:00
|
|
|
#region 中台推送管理
|
2024-05-24 06:48:53 +00:00
|
|
|
|
|
|
|
|
private static int _messageRetry = 0;
|
|
|
|
|
public static void SetPushNotificationEnabled(bool enabled)
|
|
|
|
|
{
|
2024-07-31 04:56:01 +00:00
|
|
|
DeviceInfoUploadRequest request = (DeviceInfoUploadRequest) new DeviceInfoUploadRequest()
|
2024-05-24 06:48:53 +00:00
|
|
|
.SetRetryTimes(1)
|
|
|
|
|
.SetSuccessCallBack(() =>
|
|
|
|
|
{
|
|
|
|
|
_messageRetry = 0;
|
|
|
|
|
Debug.Log($"[SDK] --- Set Push Enabled: {enabled} success");
|
|
|
|
|
})
|
|
|
|
|
.SetFailCallBack(() =>
|
|
|
|
|
{
|
|
|
|
|
double retryDelay = Math.Pow(2, _messageRetry);
|
|
|
|
|
_messageRetry++;
|
|
|
|
|
CoroutineHelper.Instance.StartDelayed((float)retryDelay, ()=> SetPushNotificationEnabled(enabled));
|
2024-07-31 04:56:01 +00:00
|
|
|
});
|
2024-05-24 06:48:53 +00:00
|
|
|
|
2024-07-31 04:56:01 +00:00
|
|
|
if (request == null) return;
|
|
|
|
|
|
|
|
|
|
request.SetPushEnabled(enabled);
|
|
|
|
|
request.Send();
|
2024-05-24 06:48:53 +00:00
|
|
|
}
|
2024-07-12 02:29:30 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Deeplink
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加回调链接
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="deeplink"></param>
|
|
|
|
|
private void OnDeeplinkCallback(string deeplink)
|
|
|
|
|
{
|
2024-07-30 12:31:41 +00:00
|
|
|
Callbacks.SDK.InvokeDeeplinkCallback(deeplink); // 尝试调用回调
|
2024-07-12 02:29:30 +00:00
|
|
|
}
|
2024-06-21 06:39:55 +00:00
|
|
|
|
2024-07-26 03:08:31 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 网络状态上报
|
|
|
|
|
|
|
|
|
|
private NetworkStatusMonitor _networkStatusMonitor;
|
2024-07-31 16:17:01 +00:00
|
|
|
private string _lastNetworkStatus;
|
2024-07-26 03:08:31 +00:00
|
|
|
|
|
|
|
|
private void InitNetworkMonitor()
|
|
|
|
|
{
|
2024-08-06 19:28:44 +00:00
|
|
|
_networkStatusMonitor = new NetworkStatusMonitor(Analytics.SetNetworkStatus,
|
|
|
|
|
lastStatus =>
|
2024-07-31 16:17:01 +00:00
|
|
|
{
|
|
|
|
|
LogEvent("guru_offline", new Dictionary<string, dynamic>()
|
|
|
|
|
{
|
|
|
|
|
["from"] = lastStatus
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-07-26 06:38:55 +00:00
|
|
|
}
|
2024-07-31 16:17:01 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取当前的网络状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private string GetNetworkStatus() => _networkStatusMonitor.GetNetworkStatus();
|
2024-07-26 06:38:55 +00:00
|
|
|
|
2024-07-31 16:17:01 +00:00
|
|
|
|
2024-07-31 12:59:36 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Firebase 服务
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动 Firebase 服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void StartFirebaseService()
|
|
|
|
|
{
|
|
|
|
|
FirebaseUtil.Init(OnFirebaseDepsCheckResult,
|
|
|
|
|
OnGetFirebaseId,
|
|
|
|
|
OnGetGuruUID,
|
|
|
|
|
OnFirebaseLoginResult); // 确保所有的逻辑提前被调用到
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGetGuruUID(bool success)
|
|
|
|
|
{
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Model.UserId = IPMConfig.IPM_UID;
|
|
|
|
|
if (GuruIAP.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
GuruIAP.Instance.SetUID(UID);
|
|
|
|
|
GuruIAP.Instance.SetUUID(UUID);
|
|
|
|
|
}
|
2024-08-06 19:28:44 +00:00
|
|
|
|
|
|
|
|
// 自打点设置用户 ID
|
2024-08-07 14:10:22 +00:00
|
|
|
Analytics.SetUid(UID);
|
2024-08-11 07:03:13 +00:00
|
|
|
// Crashlytics 设置 uid
|
|
|
|
|
CrashlyticsAgent.SetUserId(UID);
|
2024-08-07 14:10:22 +00:00
|
|
|
// 上报所有的事件
|
|
|
|
|
Analytics.ShouldFlushGuruEvents();
|
2024-07-31 12:59:36 +00:00
|
|
|
}
|
2024-08-06 19:28:44 +00:00
|
|
|
|
|
|
|
|
Callbacks.SDK.InvokeOnGuruUserAuthResult(success);
|
2024-07-31 12:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGetFirebaseId(string fid)
|
|
|
|
|
{
|
|
|
|
|
// 初始化 Adjust 服务
|
|
|
|
|
InitAdjustService(fid, InitConfig.OnAdjustDeeplinkCallback);
|
|
|
|
|
// 初始化自打点
|
2024-08-01 04:45:33 +00:00
|
|
|
Analytics.InitGuruAnalyticService(fid);
|
2024-08-11 11:35:56 +00:00
|
|
|
|
|
|
|
|
//---------- Event SDK Info ------------
|
|
|
|
|
LogI($"#6.0 --- SDK is ready, report Info ---");
|
|
|
|
|
LogSDKInfo((DateTime.UtcNow - _initTime).TotalSeconds);
|
2024-07-31 12:59:36 +00:00
|
|
|
}
|
2024-08-11 07:35:43 +00:00
|
|
|
|
|
|
|
|
// TODO: 需要之后用宏隔离应用和实现
|
|
|
|
|
// Auth 登录认证
|
|
|
|
|
private void OnFirebaseLoginResult(bool success, Firebase.Auth.FirebaseUser firebaseUser)
|
2024-07-31 12:59:36 +00:00
|
|
|
{
|
2024-08-15 05:53:44 +00:00
|
|
|
_firebaseUser = firebaseUser;
|
2024-08-11 07:35:43 +00:00
|
|
|
Callbacks.SDK.InvokeOnFirebaseAuthResult(success, firebaseUser);
|
2024-07-31 12:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始各种组件初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OnFirebaseDepsCheckResult(bool success)
|
|
|
|
|
{
|
|
|
|
|
LogI($"#3 --- On FirebaseDeps: {success} ---");
|
|
|
|
|
IsFirebaseReady = success;
|
|
|
|
|
Callbacks.SDK.InvokeOnFirebaseReady(success);
|
|
|
|
|
|
|
|
|
|
Analytics.OnFirebaseInitCompleted();
|
|
|
|
|
|
|
|
|
|
LogI($"#3.5 --- Call InitRemoteConfig ---");
|
|
|
|
|
// 开始Remote Manager初始化
|
2024-08-08 18:40:36 +00:00
|
|
|
|
|
|
|
|
var defaultGuruServiceJson = LoadDefaultGuruServiceJson();
|
|
|
|
|
|
|
|
|
|
var dict = _initConfig.DefaultRemoteData.ToDictionary(
|
|
|
|
|
entry => entry.Key,
|
|
|
|
|
entry => entry.Value);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(defaultGuruServiceJson))
|
|
|
|
|
{
|
|
|
|
|
dict[ServicesConfigKey] = defaultGuruServiceJson;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemoteConfigManager.Init(dict);
|
2024-07-31 12:59:36 +00:00
|
|
|
RemoteConfigManager.OnFetchCompleted += OnFetchRemoteCallback;
|
|
|
|
|
|
|
|
|
|
LogI($"#4 --- Apply remote services config ---");
|
|
|
|
|
// 根据缓存的云控配置来初始化参数
|
|
|
|
|
InitAllGuruServices();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Adjust服务
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动 Adjust 服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void InitAdjustService(string firebaseId, Action<string> onDeeplinkCallback = null)
|
|
|
|
|
{
|
|
|
|
|
// 启动 AdjustService
|
|
|
|
|
string appToken = GuruSettings.Instance.AdjustSetting?.GetAppToken() ?? "";
|
|
|
|
|
string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId;
|
|
|
|
|
|
2024-08-06 19:28:44 +00:00
|
|
|
// if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ID))
|
|
|
|
|
// Analytics.SetAdjustId(IPMConfig.ADJUST_ID); // 二次启动后,若有值则立即上报属性
|
2024-08-07 05:49:07 +00:00
|
|
|
|
2024-08-07 14:10:22 +00:00
|
|
|
AdjustService.Instance.Start(appToken, fbAppId, firebaseId, DeviceId,
|
2024-08-06 19:28:44 +00:00
|
|
|
OnAdjustInitComplete, onDeeplinkCallback ,OnGetGoogleAdId );
|
2024-07-31 12:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 19:28:44 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adjust 初始化结束
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="adjustId"></param>
|
|
|
|
|
/// <param name="idfv"></param>
|
|
|
|
|
/// <param name="idfa"></param>
|
|
|
|
|
private static void OnAdjustInitComplete(string adjustId, string idfv, string idfa)
|
2024-07-31 12:59:36 +00:00
|
|
|
{
|
2024-08-06 19:28:44 +00:00
|
|
|
Debug.Log($"{Tag} --- OnAdjustInitComplete: adjustId:{adjustId} idfv:{idfv} idfa:{idfa}");
|
|
|
|
|
|
2024-07-31 12:59:36 +00:00
|
|
|
// 获取 ADID
|
2024-08-06 19:28:44 +00:00
|
|
|
if (string.IsNullOrEmpty(adjustId)) adjustId = "not_set";
|
|
|
|
|
if (string.IsNullOrEmpty(idfv)) idfv = "not_set";
|
|
|
|
|
if (string.IsNullOrEmpty(idfa)) idfa = "not_set";
|
|
|
|
|
|
|
|
|
|
IPMConfig.ADJUST_ID = adjustId;
|
2024-08-07 05:49:07 +00:00
|
|
|
IPMConfig.ADJUST_IDFV = idfv;
|
|
|
|
|
IPMConfig.ADJUST_IDFA = idfa;
|
2024-08-06 19:28:44 +00:00
|
|
|
|
|
|
|
|
Analytics.SetAdjustId(adjustId);
|
|
|
|
|
Analytics.SetIDFV(idfv);
|
|
|
|
|
Analytics.SetIDFA(idfa);
|
2024-07-31 12:59:36 +00:00
|
|
|
Analytics.OnAdjustInitComplete();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 19:28:44 +00:00
|
|
|
private static void OnGetGoogleAdId(string googleAdId)
|
2024-07-31 12:59:36 +00:00
|
|
|
{
|
2024-08-06 19:28:44 +00:00
|
|
|
Debug.Log($"{Tag} --- OnGetGoogleAdId: {googleAdId}");
|
|
|
|
|
// IPMConfig.ADJUST_GOOGLE_ADID = googleAdId;
|
|
|
|
|
Analytics.SetGoogleAdId(googleAdId);
|
2024-07-31 12:59:36 +00:00
|
|
|
}
|
2024-08-06 19:28:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-24 06:48:53 +00:00
|
|
|
#endregion
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|
2024-07-31 16:17:01 +00:00
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
}
|