- Home /
persistentDataPath not working on iOS. UNITY 4.PRO.
Trying to save replay data to the device. It works on the Editor, works on Mac builds, works on Android. but doesnt work on iOS.
Im on UNITY 4.0.1f2 ..Pro for everything.
Ive read a bunch about the data path issue on the net..but they all say that since 3.3, Unity will add the /Documents path to the iOS builds..
i displayed the filepath on the iOS device when it read/writes and its correct.
/var/mobile/Applications/xxxxx-xx-x-xx-xxxx/Documents/Replay_1.bin
string dataPath = Application.persistentDataPath;
string filename = dataPath+"/replay_"+this.gameLevel+".bin";
Debug.Log ("Loading from DISK!"+filename);
this.myDebug.text = filename;
using (Stream stream = File.Open(filename, FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
this._gameCommandList = (List<GameCommand>)bin.Deserialize(stream);
stream.Close ();
}
and for saving..
string dataPath = Application.persistentDataPath;
string filename = dataPath+"/replay_"+this.gameLevel+".bin";
this.myDebug.text = filename;
Debug.Log( "Saving to disk!" + filename);
using (Stream stream = File.Open(filename, FileMode.Create))
{
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, this._gameCommandList);
stream.Close ();
}
P.S. i tried doing a search on this website..but the server times out :(
so close..yet so far..
Answer by RobDog · Feb 25, 2013 at 03:36 PM
ok..think i found out the issue..
i wrapped the code with try/catch blocks..
printing out the exception didnt tell me anything.. so i had to dig in deeper and print out the innerException message.
which told me that it could not JustInTime compile my << List >> .. and thats its in AOT-ONLY something or other..
AOT = Ahead of Time compiling.. the iPhone (Apple) does not allow JustInTime compiling on the device..
Now.. if you start searching Answers with key works "iOS JIT AOT".. you get a bunch of hits! All the different ways Unity/C# is trying to JIT on an iOS device.
Oh well.. pretty bummed since that serialized code above was SOOO DAMN easy. now i gotta go "OLD SCHOOL" on it.
based on reading a few of those hits..im going to guess this JIT/AOT thing is going to bite me again.. test test test test ! especially on the devices! and throw a crap load of try/catches in your code
@RobDog You might find this useful: http://answers.unity3d.com/questions/30930/why-did-my-binaryserialzer-stop-working.html
Your answer
Follow this Question
Related Questions
How to download asset bundles and storing it locally in ios 0 Answers
Application.persistentDataPath not working on ios but working on Mac Editor and Android 1 Answer
Delete screenshots from Gallery 0 Answers
Persistent data path changes every time a new version of the IOS app is generated 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers