|
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|
|
#if UNITY_ANDROID
|
|
#if UNITY_ANDROID
|
|
|
using System;
|
|
using System;
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+
|
|
|
#if UNITY_IPHONE
|
|
#if UNITY_IPHONE
|
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Collections;
|
|
using System.Collections;
|
|
@@ -183,6 +184,7 @@ public static class TalkingDataSDK
|
|
|
{
|
|
{
|
|
|
unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
|
unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
AndroidJavaObject activity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
|
|
AndroidJavaObject activity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
|
|
|
return activity;
|
|
return activity;
|
|
|
}
|
|
}
|
|
@@ -194,7 +196,8 @@ public static class TalkingDataSDK
|
|
|
{
|
|
{
|
|
|
int count = parameters.Count;
|
|
int count = parameters.Count;
|
|
|
map = new AndroidJavaObject("java.util.HashMap", count);
|
|
map = new AndroidJavaObject("java.util.HashMap", count);
|
|
|
- IntPtr method_Put = AndroidJNIHelper.GetMethodID(map.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
|
|
|
|
|
|
+ IntPtr method_Put = AndroidJNIHelper.GetMethodID(map.GetRawClass(), "put",
|
|
|
|
|
+ "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
|
|
object[] args = new object[2];
|
|
object[] args = new object[2];
|
|
|
foreach (KeyValuePair<string, object> kvp in parameters)
|
|
foreach (KeyValuePair<string, object> kvp in parameters)
|
|
|
{
|
|
{
|
|
@@ -205,6 +208,7 @@ public static class TalkingDataSDK
|
|
|
AndroidJNI.CallObjectMethod(map.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
|
|
AndroidJNI.CallObjectMethod(map.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
@@ -250,6 +254,7 @@ public static class TalkingDataSDK
|
|
|
{
|
|
{
|
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
talkingdataClass.CallStatic("setConfig", config.javaObj);
|
|
talkingdataClass.CallStatic("setConfig", config.javaObj);
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
@@ -265,10 +270,12 @@ public static class TalkingDataSDK
|
|
|
{
|
|
{
|
|
|
dz.SetStatic("a", 2);
|
|
dz.SetStatic("a", 2);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (talkingdataClass == null)
|
|
if (talkingdataClass == null)
|
|
|
{
|
|
{
|
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
AndroidJavaObject activity = GetCurrentActivity();
|
|
AndroidJavaObject activity = GetCurrentActivity();
|
|
|
talkingdataClass.CallStatic("initSDK", activity, appId, channelId, custom);
|
|
talkingdataClass.CallStatic("initSDK", activity, appId, channelId, custom);
|
|
|
#endif
|
|
#endif
|
|
@@ -320,37 +327,45 @@ public static class TalkingDataSDK
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static string deviceId = null;
|
|
private static string deviceId = null;
|
|
|
|
|
+
|
|
|
public static string GetDeviceId()
|
|
public static string GetDeviceId()
|
|
|
{
|
|
{
|
|
|
- if (deviceId == null && Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
|
|
|
|
+ if (deviceId == null && Application.platform != RuntimePlatform.OSXEditor &&
|
|
|
|
|
+ Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
{
|
|
{
|
|
|
#if UNITY_ANDROID
|
|
#if UNITY_ANDROID
|
|
|
if (talkingdataClass == null)
|
|
if (talkingdataClass == null)
|
|
|
{
|
|
{
|
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
deviceId = talkingdataClass.CallStatic<string>("getDeviceId", GetCurrentActivity());
|
|
deviceId = talkingdataClass.CallStatic<string>("getDeviceId", GetCurrentActivity());
|
|
|
#endif
|
|
#endif
|
|
|
#if UNITY_IPHONE
|
|
#if UNITY_IPHONE
|
|
|
deviceId = TDGetDeviceId();
|
|
deviceId = TDGetDeviceId();
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return deviceId;
|
|
return deviceId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static string oaid = null;
|
|
private static string oaid = null;
|
|
|
|
|
+
|
|
|
public static string GetOAID()
|
|
public static string GetOAID()
|
|
|
{
|
|
{
|
|
|
- if (oaid == null && Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
|
|
|
|
+ if (oaid == null && Application.platform != RuntimePlatform.OSXEditor &&
|
|
|
|
|
+ Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
{
|
|
{
|
|
|
#if UNITY_ANDROID
|
|
#if UNITY_ANDROID
|
|
|
if (talkingdataClass == null)
|
|
if (talkingdataClass == null)
|
|
|
{
|
|
{
|
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
oaid = talkingdataClass.CallStatic<string>("getOAID", GetCurrentActivity());
|
|
oaid = talkingdataClass.CallStatic<string>("getOAID", GetCurrentActivity());
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return oaid;
|
|
return oaid;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -363,6 +378,7 @@ public static class TalkingDataSDK
|
|
|
{
|
|
{
|
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
talkingdataClass = new AndroidJavaClass(TALKINGDATA_CLASS);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
talkingdataClass.CallStatic("setVerboseLogDisable");
|
|
talkingdataClass.CallStatic("setVerboseLogDisable");
|
|
|
#endif
|
|
#endif
|
|
|
#if UNITY_IPHONE
|
|
#if UNITY_IPHONE
|
|
@@ -429,7 +445,8 @@ public static class TalkingDataSDK
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void OnRegister(string profileId, TalkingDataProfile profile, string invitationCode, Dictionary<string, object> eventValue)
|
|
|
|
|
|
|
+ public static void OnRegister(string profileId, TalkingDataProfile profile, string invitationCode,
|
|
|
|
|
+ Dictionary<string, object> eventValue)
|
|
|
{
|
|
{
|
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
{
|
|
{
|
|
@@ -483,11 +500,12 @@ public static class TalkingDataSDK
|
|
|
talkingdataClass.CallStatic("onProfileUpdate", profile.javaObj);
|
|
talkingdataClass.CallStatic("onProfileUpdate", profile.javaObj);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
-#if UNITY_IPHONE
|
|
|
|
|
|
|
+#if UNITY_IPHONE
|
|
|
TDOnProfileUpdate(profile.ToString());
|
|
TDOnProfileUpdate(profile.ToString());
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
public static void OnCreateCard(string profileId, string method, string content)
|
|
public static void OnCreateCard(string profileId, string method, string content)
|
|
|
{
|
|
{
|
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
@@ -992,7 +1010,8 @@ public static class TalkingDataSDK
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- public static void OnEvent(string eventId, Dictionary<string, object> parameters, Dictionary<string, object> eventValue)
|
|
|
|
|
|
|
+ public static void OnEvent(string eventId, Dictionary<string, object> parameters,
|
|
|
|
|
+ Dictionary<string, object> eventValue)
|
|
|
{
|
|
{
|
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
{
|
|
{
|
|
@@ -1006,6 +1025,7 @@ public static class TalkingDataSDK
|
|
|
{
|
|
{
|
|
|
parametersMap.Dispose();
|
|
parametersMap.Dispose();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (eventValueMap != null)
|
|
if (eventValueMap != null)
|
|
|
{
|
|
{
|
|
|
eventValueMap.Dispose();
|
|
eventValueMap.Dispose();
|
|
@@ -1020,6 +1040,68 @@ public static class TalkingDataSDK
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 手动报告错误
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public static void OnError(string message, string stackTrace, LogType logType)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
|
|
+ {
|
|
|
|
|
+#if UNITY_ANDROID
|
|
|
|
|
+ if (talkingdataClass != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ string exceptionMessage = $"{logType}: {message}\n{stackTrace}";
|
|
|
|
|
+ using (AndroidJavaObject javaException = new AndroidJavaObject("java.lang.Exception", exceptionMessage))
|
|
|
|
|
+ {
|
|
|
|
|
+ talkingdataClass.CallStatic("onError", unityPlayerClass, javaException);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 手动报告异常
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public static void ReportException(System.Exception exception)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
|
|
|
+ {
|
|
|
|
|
+#if UNITY_ANDROID
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ using (AndroidJavaObject javaException = new AndroidJavaObject("java.lang.Exception",
|
|
|
|
|
+ $"{exception.Message}\n{exception.StackTrace}"))
|
|
|
|
|
+ {
|
|
|
|
|
+ talkingdataClass.CallStatic("onError", unityPlayerClass, javaException);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (System.Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ Debug.LogError("报告异常到TalkingData失败: " + e.Message);
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 设置是否自动捕获未处理异常
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="enabled">true:开启, false:关闭</param>
|
|
|
|
|
+ public static void SetReportUncaughtExceptions(bool enabled)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ talkingdataClass.CallStatic("setReportUncaughtExceptions", enabled);
|
|
|
|
|
+ Debug.Log($"TalkingData自动异常捕获: {(enabled ? "开启" : "关闭")}");
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (System.Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ Debug.LogError("设置TalkingData自动异常捕获失败: " + e.Message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static void SetGlobalKV(string key, object val)
|
|
public static void SetGlobalKV(string key, object val)
|
|
|
{
|
|
{
|
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
|
|
@@ -1028,8 +1110,8 @@ public static class TalkingDataSDK
|
|
|
if (talkingdataClass != null)
|
|
if (talkingdataClass != null)
|
|
|
{
|
|
{
|
|
|
AndroidJavaObject valObject = typeof(string).IsInstanceOfType(val)
|
|
AndroidJavaObject valObject = typeof(string).IsInstanceOfType(val)
|
|
|
- ? new AndroidJavaObject("java.lang.String", val)
|
|
|
|
|
- : new AndroidJavaObject("java.lang.Double", "" + val);
|
|
|
|
|
|
|
+ ? new AndroidJavaObject("java.lang.String", val)
|
|
|
|
|
+ : new AndroidJavaObject("java.lang.Double", "" + val);
|
|
|
talkingdataClass.CallStatic("setGlobalKV", key, valObject);
|
|
talkingdataClass.CallStatic("setGlobalKV", key, valObject);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
@@ -1063,4 +1145,4 @@ public static class TalkingDataSDK
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|