Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

System.IO.File get file created in iOS documents directory

Discussion in 'Scripting' started by PDZ, Dec 18, 2015.

  1. PDZ

    PDZ

    Joined:
    Sep 12, 2013
    Posts:
    18
    I have an iOS native plugin that saves a file to the application documents directory. Upon successful completion of saving the file, I make a callback to unity with the filepath and check to see if the file exists.

    I can confirm the file does exist in the iOS documents directory, as it is a video and I load the video natively and play it. However, in C# using System.IO.File, it does not seem to be able to find it.

    Code (CSharp):
    1. void HandleRecordingSavedEvent (bool isSuccessful, string outputDir)
    2.     {
    3.         Debug.Log("Event callback for saved: " + isSuccessful + " at " + outputDir);
    4.  
    5.         _recording = false;
    6.         _endTime = Time.time;
    7.  
    8.         string[] pathComponents = outputDir.Split(new string[] { @"\/" }, System.StringSplitOptions.None);
    9.         string fileName = pathComponents[pathComponents.Length - 1];
    10.  
    11.         string myGuess = Application.persistentDataPath + @"/" + fileName;
    12.  
    13.         Debug.Log("My Guess " + myGuess);
    14.  
    15.         if (File.Exists(myGuess))
    16.             Debug.Log("I found her!");
    17.         else
    18.             Debug.Log("Cannot find");
    19.     }
    And in the console window when I run the application I get the following output

    Can anyone spot something I am doing wrong?
     
  2. PDZ

    PDZ

    Joined:
    Sep 12, 2013
    Posts:
    18
    I incorrectly assumed Mono would use and accept the same format that native iOS does.

    Adding code along the same sort of thought process as this corrects the issue

    Code (CSharp):
    1.  
    2. #ifUNITY_IOS
    3.  
    4. MatchregexMatch = Regex.Match(videoURL, "(?<=Documents)(.*)");
    5.  
    6. videoURL = Application.persistentDataPath + regexMatch.Value;
    7. #else
    8. //otherplatformsmayneedchanging
    9. #endif
    10.  
     
    Last edited: Jan 5, 2016
    LeftyRighty likes this.