diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs b/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs index 96727f1..d257169 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs @@ -1,9 +1,11 @@ + namespace Guru { using System; using System.Collections; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; using UnityEngine; /// @@ -12,7 +14,7 @@ namespace Guru public class GuruConsent { // Guru Consent Version - public static string Version = "1.0.7"; + public static string Version = "1.0.8"; public static string Tag = "[GuruConsent]"; #region 公用接口 @@ -80,19 +82,41 @@ namespace Guru //------- message send to unity ---------- Debug.Log($"{Tag} get callback msg:\n{msg}"); - - var result = JsonConvert.DeserializeObject(msg); - - if (result != null && result.action == "gdpr") + try { - if (result.data != null) + var data = JsonConvert.DeserializeObject(msg); + if (data != null && data.TryGetValue("action", out var jAtc)) { - Debug.Log($"{Tag} --- status: {result.data.status} msg: {result.data.msg}"); - onCompleteHandler?.Invoke(result.data.status); - return; + if (jAtc.ToString() == "gdpr") + { + if(data.TryGetValue("data", out var jData)) + { + if (jData is JObject jObj) + { + int status = StatusCode.UNKNOWN; + string message = ""; + if (jObj.TryGetValue("status", out var jStatus)) + { + int.TryParse(jStatus.ToString(), out status); + } + if (jObj.TryGetValue("msg", out var jMsg)) + { + message = jMsg.ToString(); + } + Debug.Log($"{Tag} --- status: {status} msg: {message}"); + onCompleteHandler?.Invoke(status); + return; + } + } + + } } } - + catch (Exception ex) + { + Analytics.LogCrashlytics(ex); + } + Debug.LogError($"{Tag} Parse callback Error"); onCompleteHandler?.Invoke(StatusCode.UNKNOWN); } @@ -110,26 +134,6 @@ namespace Guru #region 常量定义 - /// - /// GDPR 状态对象 - /// - [Serializable] - internal class ConsentResult - { - public string action = ""; - public ConsentStatus data = null; - } - - /// - /// GDPR 状态对象 - /// - [Serializable] - internal class ConsentStatus - { - public int status; - public string msg; - } - /// /// Consent 状态 ///