fix: 修复 GuruConset 的 Json 解析失败导致回调不执行的 BUG

deeplink
胡宇飞 2024-02-28 15:00:26 +08:00
parent 69cb6fa1f1
commit 18656daec0
1 changed files with 20 additions and 14 deletions

View File

@ -77,22 +77,20 @@ namespace Guru
//------- message send to unity ---------- //------- message send to unity ----------
Debug.Log($"{Tag} get callback msg:\n{msg}"); Debug.Log($"{Tag} get callback msg:\n{msg}");
var ditc = JsonConvert.DeserializeObject<Dictionary<string, string>>(msg); var result = JsonConvert.DeserializeObject<ConsentResult>(msg);
if (ditc != null && ditc.ContainsKey("action") && ditc["action"] == "gdpr") if (result != null && result.action == "gdpr")
{ {
var json = ditc["data"]; if (result.data != null)
var status = JsonConvert.DeserializeObject<ConsentStatus>(json);
if (status != null)
{ {
Debug.Log($"{Tag} --- status: {status.status} msg: {status.msg}"); Debug.Log($"{Tag} --- status: {result.data.status} msg: {result.data.msg}");
onCompleteHandler?.Invoke(status.status); onCompleteHandler?.Invoke(result.data.status);
return;
} }
} }
else
{ Debug.LogError($"{Tag} Parse callback Error");
Debug.Log($"{Tag} Parse callback Error"); onCompleteHandler?.Invoke(StatusCode.UNKNOWN);
}
} }
/// <summary> /// <summary>
@ -107,7 +105,16 @@ namespace Guru
#endregion #endregion
#region 常量定义 #region 常量定义
/// <summary>
/// GDPR 状态对象
/// </summary>
[Serializable]
internal class ConsentResult
{
public string action = "";
public ConsentStatus data = null;
}
/// <summary> /// <summary>
/// GDPR 状态对象 /// GDPR 状态对象
@ -118,8 +125,7 @@ namespace Guru
public int status; public int status;
public string msg; public string msg;
} }
/// <summary> /// <summary>
/// Consent 状态 /// Consent 状态
/// </summary> /// </summary>