System.IO.File problem

Hello

I’ve been browsing the forums and everywhere to be honest, but with no lucky, at least not with recent posts (2008+).

I am developing an App that is designed to read a XML in a web server and check for its contents. By reading the XML, the App should know which images it should download to display (it is like a dynamic catalog). My idea was, create a Web interface for my client to update the XML and upload the new images, and access the XML thru the WWW class. Then, check if the web XML is different from the local XML (if it exists), overwrite the local XML, and download the required images, if they dont exist also. I need to store these files in a more permanent way, so that if they close the App, they are still there.

My first try was with the System.IO.File class… and it does work perfectly on my machine, but as soon as I try it running on the iPad, it doesnt work.

Here is my code, its very simple:

//To select the correct location
docPath = Application.dataPath;
if(Application.platform == RuntimePlatform.IPhonePlayer)
{
	docPath = docPath.Substring(0, docPath.Length - 5);
	docPath = docPath.Substring(0, docPath.LastIndexOf('/')) + "/Documents";
}
		
StartCoroutine(ReadXML(docPath + "/fila-info.xml", 3));

And the read/write code is:

private IEnumerator ReadXML(string file, float waitTime)
{
	yield return new WaitForSeconds(waitTime);
	WWW tempWWW = new WWW(GlobalValues.domainAddress + "/file.xml");
	yield return tempWWW;
	FileInfo info = new FileInfo(file);
	if(info != null || info.Exists != false)
	{
		if (!File.ReadAllText(file).Equals(tempWWW.text))
		{
			File.WriteAllText(file, tempWWW.text);
		}
		else
		{
		}
	}
	else
	{
	}
}

Problem is, it does not process the File.WriteAllText or ReadAllText, and I was using File.Exists instead of FileInfo… I am “using System.IO”… It seens to me as if this was incompatible… but if I am doing something wrong, please tell me.

Thank you for your time,
Allan

I have downloaded XML files from the web in an Unity iOS app and then deserialized them in the app.

I did that like nearly a year ago though, so I don’t remember much about it.

But just in case your doing this part wrong, the function to get the documents path of your iOS app, on iOS is this:

Application.dataPath + "/../../Documents/";

That line of code is correct, and verified working in a build just 1 week ago.

I don’t know why your File.IO code doesn’t work right, it should. You should set up some tests to make sure you can read or write any file at all.

or use Application.persistentDataPath / temporaryDataPath
They give you the right path out of the box.

And no the above path pretty surely does not work right as its pointing into the application itself which will definitely never work on iOS for write access, only for read access.

Thank you for the answers,

But unfortunately the problem persists =/. I’ve been writing the datapath to a guitext only for reference and it was correct already, but Application.persistentDataPath does the same thing so, its simpler this way.

I dont know how to debug my application on the iPad correctly… so what I did was create a cube and change its colors based on where the code stops… and it stops right here:

if(info != null || info.Exists != false)
{
     if (!File.ReadAllText(file).Equals(tempWWW.text))
     {
     }
     else
     {
     }
}

It seens to stop completely at this point, right after the if (info…), as it does not go into the If block and doesnt go to the Else block too. That is why I think it might be because System.IO.File is not working as it should…

On the player prefs I am not using any kind of stripping, and using .NET 2.0… I really dont know any other way I can work with this =/

Ok, I was trying to do this using Unity 3.5… went back to 3.4.2 and it worked fine on the device. Guessing it is a bug.