Search Unity

I can't save xml file in iOS project during the runtime! (written by unity/C#)

Discussion in 'Scripting' started by Grannel, May 9, 2019.

  1. Grannel

    Grannel

    Joined:
    Dec 9, 2018
    Posts:
    2
    Code (CSharp):
    1. FileStream fileStream = new FileStream(xmlPath, FileMode.Create);
    2.             StreamWriter streamWriter = new StreamWriter(fileStream);
    3.             streamWriter.Write(addXml.InnerXml);
    4.             streamWriter.Flush();
    5.             streamWriter.Close();
    6.  
    7.             FileStream fileStream2 = new FileStream(tempXmlPath, FileMode.Create);
    8.             StreamWriter streamWriter2 = new StreamWriter(fileStream2);
    9.             streamWriter2.Write(addXml.InnerXml);
    10.             streamWriter2.Flush();
    11.             streamWriter2.Close();
    xmlPath = Application.streamingAssetsPath + "/carDatabaseXml.xml";
    tempXmlPath = Application.persistentDataPath + "/carDatabaseXml.xml";
    I have used this way to try to save a xml file from "addXml.Xml" called "carDatabaseXml.xml",
    but I can't save the streamWriter/streamWriter in this way

    Anyone can help me?
     
  2. Grannel

    Grannel

    Joined:
    Dec 9, 2018
    Posts:
    2
    It is no problem to run in my Mac unity editor, but it can't work in iOS
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Try using Path.Combine instead of + operator. Maybe there's something wrong with the slashes or path itself.
    Also, you might want to wrap those in Try / Catch block.

    Also, attach a debugger and see if there are actual errors (via XCode). Our PSI agents just went on holiday.
     
    Grannel likes this.