Hey everybody,
I have the problem that I can enter and play my build on the Mini Ipad 2022, but I can’t re-enter it. I don’t have this if I disable my AR functions.
To be specific: I get stuck on the splash screen (without showing the icon) when I enter after close the app.
Why is this and how can I fix this?
Unity version: 2022.3.12f1
Xcode version: 15.2
Packages: Packages - Album on Imgur
I already tried to fix it with this, but sadly this makes it that leaving and entering without fully closing isn’t plossible anymore:
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class ARSessionManager : MonoBehaviour
{
private ARSession arSession;
void Awake()
{
arSession = FindObjectOfType<ARSession>();
// Initialize the AR session
if (arSession != null)
{
ResetARSession();
}
}
void Start()
{
if (arSession != null)
{
Debug.Log("AR Session started.");
}
}
// Reset ARKit when entering the scene (only call this when needed)
private void ResetARSession()
{
if (arSession != null)
{
// Stop AR session
arSession.enabled = false;
// Clear AR session state (ARKit-specific reset)
arSession.Reset();
// Restart AR session
arSession.enabled = true;
Debug.Log("AR session has been reset.");
}
}
// Handle when the app is paused or resumed
private void OnApplicationPause(bool isPaused)
{
if (arSession != null)
{
if (isPaused)
{
// App is going to the background, disable AR session
Debug.Log("App paused, stopping AR session.");
arSession.enabled = false;
}
else
{
// App is returning from background, restart AR session with a delay
Debug.Log("App resumed, restarting AR session.");
StartCoroutine(RestartARSessionWithDelay(1.0f)); // Wait 1 second before restarting
}
}
}
// Handle when the app loses or gains focus
private void OnApplicationFocus(bool hasFocus)
{
if (arSession != null)
{
if (!hasFocus)
{
// App loses focus, disable AR session
Debug.Log("App lost focus, stopping AR session.");
arSession.enabled = false;
}
else
{
// App gains focus, restart AR session with a delay
Debug.Log("App gained focus, restarting AR session.");
StartCoroutine(RestartARSessionWithDelay(1.0f)); // Add delay for smoother transitions
}
}
}
private IEnumerator RestartARSessionWithDelay(float delay)
{
yield return new WaitForSeconds(delay); // Wait for a small delay to let ARKit stabilize
if (arSession != null)
{
arSession.enabled = true;
Debug.Log("AR session restarted after delay.");
}
}
private void OnDestroy()
{
if (arSession != null)
{
arSession.Reset();
Debug.Log("AR session cleaned up on destroy.");
}
}
}```
I also tried to fix it by deleting the temp files:
```using UnityEngine;
using System.IO;
public class TempFileCleaner : MonoBehaviour
{
// Path to Unity's persistent data directory (used for storing temporary data)
private string tempFolderPath;
void Start()
{
// Initialize the temp folder path (change this if you store temp files elsewhere)
tempFolderPath = Application.temporaryCachePath;
// Delete temp files on app relaunch
DeleteTemporaryFiles();
}
// Function to delete files in the temp folder
void DeleteTemporaryFiles()
{
// Check if the folder exists
if (Directory.Exists(tempFolderPath))
{
// Get all files in the directory
string[] tempFiles = Directory.GetFiles(tempFolderPath);
// Loop through all files and delete them
foreach (string file in tempFiles)
{
try
{
// Attempt to delete the file
File.Delete(file);
Debug.Log("Deleted temp file: " + file);
}
catch (IOException ex)
{
Debug.LogError("Failed to delete temp file: " + file + "\n" + ex.Message);
}
}
Debug.Log("All temporary files deleted.");
}
else
{
Debug.Log("Temp folder not found: " + tempFolderPath);
}
}
}```