- Home /
Write and Read to a iOS device! Help
Hi everyone!
I've been working on a code for 1 1/2 day to use on iOS device. I've been using testing it on a mac, but switching it iOS didn't go well. I thought i could just switch from using Application.dataPath to peristentDataPath and it would work. But NO!
I'm not familiar with using a serializer, so i followed this example http://unitynoobs.blogspot.no/2011/04/xml-writing-to-existing-xml-file.html.
I used a StreamWriter and created a .txt file, is it a way to use these together.
I would really be greatful for a simple but a full example how to get this done :)
Thank you in advance.
What broke when you changed to ios? Can you post the error message? I would suggest making it work on $$anonymous$$ac with Application.persistentDataPath and then it should work on ios (with a couple of caveats).
Well i'm using X$$anonymous$$LDocument. xmlDoc.Load(filepath); xmlDoc.Save(filepath);
So on my mac i use string filepath = Application.dataPath + @"/Data/gamexmldata.xml"; Tried to use on my mac and it didn't work. string filepath = Application.persistentDataPath + @"/Data/gamexmldata.xml"; But it failed, i just a IF statement to chech if the "filepath" exist. On mac with dataPath works, but with persistentDataPath doesn't work.
Tried to use it on ipad and didn't work either. :(
You made a Data folder with CreateDirectory inside your Application.persistentDataPath right?
Answer by knunery · Mar 11, 2014 at 08:32 PM
This save method works for me on both my mac and iphone.
public void Save() {
Debug.Log (Application.persistentDataPath);
XmlSerializer xml = new XmlSerializer (typeof(PlayerData));
FileStream file = File.Create (Application.persistentDataPath + "/playerInfo.dat");
xml.Serialize (file, playerData);
file.Close ();
}
Your answer
Follow this Question
Related Questions
Writing a XML file to iOS 1 Answer
Saving My World 1 Answer
XmlException when trying to read/write XML from iOS device 1 Answer
Using XML for a simple webplayer Highscore Table 1 Answer
Work with XML hidden for the user? 1 Answer