MonoTouch, NSLog, and TestFlightSdk

I am trying to integrate TestFlightSdk into an application that I created using MonoTouch .

I am trying to implement logging in my application so that TestFlightSdk picks it up. It supposedly automatically collects NSLog ged text, but I can’t find the right combination of code to add to my own C # / MonoTouch application that does the same.

What I tried:

  • Console.WriteLine("...");
  • Debug.WriteLine("..."); (but I think it just calls Console.WriteLine )
  • Implementing NSLog support, but it crashed my application, so apparently I did something wrong (I will ask a new question if this is a way forward.)

Is there anything built into MonoTouch that will record log messages through NSLog so that I can use it with TestFlightSdk? Or do I need to flip my own shell for NSLog?

To implement NSLog myself, I added the following:

 public static class Logger { [DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")] private extern static void NSLog(string format, string arg1); public static void Log(string message) { NSLog("%s", message); } } 

(I got the code snippets above from this other SO question: How to link the iOS Foundations NSLog function .)

But this is a crash of my application with a SIGSEGV error.

+4
source share
3 answers
 using System; using System.Runtime.InteropServices; using MonoTouch.Foundation; public class Logger { [DllImport(MonoTouch.Constants.FoundationLibrary)] private extern static void NSLog(IntPtr message); public static void Log(string msg, params object[] args) { using (var nss = new NSString (string.Format (msg, args))) { NSLog(nss.Handle); } } } 
+7
source

Anuj pointed the way, and this is what I ended up with:

 [DllImport(MonoTouch.Constants.FoundationLibrary)] private extern static void NSLog(IntPtr format, IntPtr arg1); 

and calling him:

 using (var format = new NSString("%@")) using (var arg1 = new NSString(message)) NSLog(format.Handle, arg1.Handle); 

When I tried only one parameter, if I had percentage characters in a string, it was interpreted as an attempt to format the string, but since there were no arguments, it crashed.

+2
source

Console.WriteLine() works as expected (redirected to NSLog ) on current xamarin.ios versions. Even in versions (using hokkapp, etc.). No need to use DllImport .

0
source

Source: https://habr.com/ru/post/1395529/


All Articles