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

FileStream fileStream = new FileStream(xmlPath, FileMode.Create);
            StreamWriter streamWriter = new StreamWriter(fileStream);
            streamWriter.Write(addXml.InnerXml);
            streamWriter.Flush();
            streamWriter.Close();

            FileStream fileStream2 = new FileStream(tempXmlPath, FileMode.Create);
            StreamWriter streamWriter2 = new StreamWriter(fileStream2);
            streamWriter2.Write(addXml.InnerXml);
            streamWriter2.Flush();
            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?

It is no problem to run in my Mac unity editor, but it can’t work in iOS

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.

1 Like