Get Debug.Log output in the working iOS build

Hey so – good answer by @Mozgold but – well, first off let me note that Application.RegisterLogCallback has now been replaced – any one looking to use @Mozgold’s answer should use Application.logMessageReceivedThreaded or Application.logMessageReceived – see this thread How to use Application.logMessageReceived for logging ? - Questions & Answers - Unity Discussions

I had the same problem, but preferred instead to use a bridge to pipe Debug.Log messages to NSLog. The downside of this approach is that, in XCode’s console, you see the messages twice. The advantage is that, when running a TestFlight’d build, I see the messages live as they happen in XCode’s Window / Devices log when the app is running on my selected device.

STEP 1 – register a callback so that Debug.Log’s are piped to method in my iOS plugin

	public void OnEnable() {
		// Debug.LogWarning("------ ------ Registered log callback----- ---------");
		Application.logMessageReceived += IOSPlugin.LogToiOS;

	public void OnDisable() {
		Application.logMessageReceived -= IOSPlugin.LogToiOS;

STEP 2 – implement method in my iOSPlugin to pipe these calls to the native app

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class IOSPlugin : MonoBehaviour {

	[DllImport ("__Internal")]
	private static extern void _logToiOS(string debugMessage);

	public static void LogToiOS(string logString, string stackTrace, LogType type) {
		// We check for UNITY_IPHONE again so we don't try this if it isn't iOS platform.
		// Now we check that it's actually an iOS device/simulator, not the Unity Player. You only get plugins on the actual device or iOS Simulator.
		if (Application.platform == RuntimePlatform.IPhonePlayer) {
			_logToiOS(logString + "

" + stackTrace);

STEP 3 – implement a method in my iOS app’s to pipe this to NSLog – you should be able to just directly drop this in your and be all set

extern "C" {
    void _logToiOS(const char* debugMessage) {
 		NSLog(@"Received _logToiOS %@", [NSString stringWithUTF8String:debugMessage]);