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 :frowning:

so close…yet so far…

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

I was facing same issue.My ProductName was wrong,containing space, used for bundle identifier, to get persistentDataPath. so I resolved my issue :slight_smile: