From 84a3ff1b330909c9703062310c5a78cb1a9965e2 Mon Sep 17 00:00:00 2001 From: Vijay Sharma Date: Wed, 13 May 2020 16:15:28 -0400 Subject: [PATCH] Added logException --- Plugins/TestFairy.cs | 15 +++++++++++++++ Plugins/iOS/TestFairyUnityWrapper.m | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/Plugins/TestFairy.cs b/Plugins/TestFairy.cs index 985cfee..b63b775 100644 --- a/Plugins/TestFairy.cs +++ b/Plugins/TestFairy.cs @@ -53,6 +53,9 @@ public class TestFairy : MonoBehaviour [DllImport("__Internal")] private static extern void TestFairy_log(string name); + [DllImport("__Internal")] + private static extern void TestFairy_logException(string name, string trace); + [DllImport("__Internal")] private static extern void TestFairy_hideWebViewElements(string cssSelector); @@ -337,6 +340,18 @@ public static void log(string message) { #endif } + public static void logException(string message, string stacktrace) { +#if UNITY_IPHONE && !UNITY_EDITOR + TestFairy_logException(message, stacktrace); +#elif UNITY_ANDROID && !UNITY_EDITOR + using(AndroidJavaClass pluginClass = getTestFairyClass()) { + if(pluginClass != null) { + pluginClass.CallStatic("logThrowable", "TestFairyUnity", stacktrace); + } + } +#endif + } + public static void hideWebViewElements(string cssSelector) { #if UNITY_IPHONE && !UNITY_EDITOR TestFairy_hideWebViewElements(cssSelector); diff --git a/Plugins/iOS/TestFairyUnityWrapper.m b/Plugins/iOS/TestFairyUnityWrapper.m index 39d357a..c3ce51d 100755 --- a/Plugins/iOS/TestFairyUnityWrapper.m +++ b/Plugins/iOS/TestFairyUnityWrapper.m @@ -136,6 +136,14 @@ void TestFairy_log(char *message) { TFLog(@"%@", value); } +void TestFairy_logException(char *message, char *trace) { + NSString *messageString = message == NULL ? @"" : [NSString stringWithUTF8String:message]; + NSString *traceString = trace == NULL ? @"" : [NSString stringWithUTF8String:trace]; + + NSError *error = [NSError errorWithDomain:@"com.testfairy.unity" code:-1 userInfo:@{NSLocalizedDescriptionKey: messageString}]; + [TestFairy logError:error stacktrace:[traceString componentsSeparatedByString:@"\n"]]; +} + void TestFairy_hideWebViewElements(char *cssSelector) { if (cssSelector == NULL) { return;