Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

IsolatedStorageException!

Discussion in 'iOS and tvOS' started by 3dgrinder, May 3, 2010.

  1. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Hi all,

    I was trying to save a text file in my app and it's giving following error:

    Code (csharp):
    1. IsolatedStorageException: Could not find a part of the path "/var/mobile/Applications/1FAA8890-EC61-4955-B8A5-13A94B3486DD/MyApp.app/Documents/test.xml".
    2. System.IO.File.Create (System.String path)
    3. MyController.Start ()
    4.  
    5. (Filename:  Line: -1)
    I know about Application.dataPath. I have tried following way to generate the path:
    Code (csharp):
    1.         string fpath = Application.dataPath;
    2.         string fileName = fpath.Substring (0, fpath.Length - 4) + "Documents/test.xml";
    3.  
    and
    Code (csharp):
    1.                     fpath = Application.dataPath;
    2.                     fileName=fpath.Substring(0, fpath.LastIndexOf("/")) + "/Documents/test.xml";
    3.  
    Any idea about it?

    Thanks
    -grinder
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The template for the data path on the iPhone is:-

    <path to player app bundle>/<AppName.app>/Data

    You just need to concatenate a slash and the name of the file to the end of the string returned by Application.dataPath.
     
    hitarthdoc1994 likes this.
  3. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    That will give:
    Code (csharp):
    1. UnauthorizedAccessException: Access to the path "/var/mobile/Applications/895972FF-19CB-470C-9685-A5D65024D07E/MyApp.app/Data/test.txt" is denied.
    2. System.IO.File.Create (System.String path)
    3. MyController.Start ()
    4.  
    5. (Filename:  Line: -1)
    6.  
    iPhone only permit to write data at application's document directory.
     
  4. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
    Any progress?

    I have the same thing...
     
  5. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Your game has read+write access to
    Code (csharp):
    1. /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
    2.  
    and Application.dataPath returns
    Code (csharp):
    1. /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
    Please see the following page in Unity manual for a code sample:
    Unity Manual > Getting Started with iPhone Development > Preparing your application for "In App Purchases"
     
  6. Pokarev

    Pokarev

    Joined:
    Oct 12, 2012
    Posts:
    3
    Here is my function
    Code (CSharp):
    1. public string IOSPath {
    2.         get {
    3.             #if UNITY_EDITOR
    4.             return Application.dataPath + "/";
    5.             #endif
    6.             #if UNITY_IOS
    7.             string deviceIosPathTemplateStr = "/var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/";
    8.             return Application.dataPath.Substring(0, deviceIosPathTemplateStr.Length) + "Documents/";
    9.             #endif
    10.         }
    11.     }
     
  7. amanpu

    amanpu

    Joined:
    Feb 12, 2015
    Posts:
    8
    I also came across this issue and I solved it by just putting test.xml file into Resources folder. And then use Resources.Load() to load file
    1. TextAsset textAsset = (TextAsset) Resources.Load("test");
      xmlDoc.LoadXml (textAsset.text);
     
    Last edited: Feb 15, 2016