Search Unity

Question Console Log from AR app on iPhone (Solved)

Discussion in 'AR' started by vladstorm, Dec 22, 2022.

  1. vladstorm

    vladstorm

    Joined:
    Oct 4, 2021
    Posts:
    9
    hi everyone,
    sorry for a noob question but how can i see a console log from the app running on iPhone?

    I have a bug but i can't figure out what it is. I'm using AR Foundation 5 + URP.
    I dont see anything in xcode console.
     
    Last edited: Dec 29, 2022
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    When you build a project for the iOS build target in Unity, this produces an Xcode project.

    Open Xcode, then build your app for your target device. The console logs are visible in Xcode.
     
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
  4. vladstorm

    vladstorm

    Joined:
    Oct 4, 2021
    Posts:
    9
    Well, all I wanted is to see the unity console log on the screen of the device when running an app. In case something wrong is happening. Xcode log is useless 'cause it doesnt show unity log.

    Anyways, I figured it out. Here's the script if anyone needs it.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System;
    5.  
    6. public class LogOnScreen : MonoBehaviour{
    7.  
    8.    public uint qsize = 15;  // number of messages to keep
    9.    public int fontSize = 40;
    10.    Queue myLogQueue = new Queue();
    11.  
    12.    void Start() {
    13.       Debug.Log("Started up logging.");
    14.    }
    15.  
    16.    void OnEnable() {
    17.       Application.logMessageReceived += HandleLog;
    18.    }
    19.  
    20.    void OnDisable() {
    21.       Application.logMessageReceived -= HandleLog;
    22.    }
    23.  
    24.    void HandleLog(string logString, string stackTrace, LogType type) {
    25.       myLogQueue.Enqueue("[" + type + "] " + logString);
    26.       if(type == LogType.Exception) myLogQueue.Enqueue(stackTrace);
    27.       while (myLogQueue.Count > qsize)
    28.          myLogQueue.Dequeue();
    29.     }
    30.  
    31.    void OnGUI() {
    32.       GUI.skin.label.fontSize = fontSize;
    33.       GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
    34.       GUILayout.Label("\n" + string.Join("\n", myLogQueue.ToArray()));
    35.       GUILayout.EndArea();
    36.    }
    37. }
     
    thehen2 likes this.