Created
March 24, 2017 19:10
-
-
Save dannycabrera/7ed8e28626215a3cde8c661c0eed0d98 to your computer and use it in GitHub Desktop.
NSLog workaround for Xamarin Console.WriteLine bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const string FoundationLibrary = "/System/Library/Frameworks/Foundation.framework/Foundation"; | |
[System.Runtime.InteropServices.DllImport(FoundationLibrary)] | |
extern static void NSLog(IntPtr format, IntPtr s); | |
[System.Runtime.InteropServices.DllImport(FoundationLibrary, EntryPoint = "NSLog")] | |
extern static void NSLog_ARM64(IntPtr format, IntPtr p2, IntPtr p3, IntPtr p4, IntPtr p5, IntPtr p6, IntPtr p7, IntPtr p8, IntPtr s); | |
static readonly bool Is64Bit = IntPtr.Size == 8; | |
static readonly bool IsDevice = ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.DEVICE; | |
static readonly Foundation.NSString nsFormat = new Foundation.NSString(@"%@"); | |
static void OutputStringToConsole(string text) | |
{ | |
using (var nsText = new Foundation.NSString(text)) | |
{ | |
if (IsDevice && Is64Bit) | |
{ | |
NSLog_ARM64(nsFormat.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, nsText.Handle); | |
} | |
else | |
{ | |
NSLog(nsFormat.Handle, nsText.Handle); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From: https://forums.xamarin.com/discussion/86226/console-writeline-blank-in-device-log