WWW error on ios

Hi

Recently I’m testing my project and find it always return bad url(www.error) when attempt to load file from local disk on ios simulator.
But in editor, it works fine.

Here’s a sample, it fail on simulator, but i can find this file from terminal, so the path is correct. Maybe we can’t use “file://” in ios?

void Start ()
	{
		Write ();
		StartCoroutine (Read ("file://" + Application.persistentDataPath + "/a.txt"));	
	}
	
	void Write ()
	{
		File.WriteAllText (Application.persistentDataPath + "/a.txt", "Hello world");		
	}

	IEnumerator Read (string path)
	{
		NGUIDebug.Log ("Reading: " + path);
		WWW www = new WWW (path);
		yield return www;
		
		if (www.isDone && www.error == null) {
			NGUIDebug.Log ("WWW result:" + www.text);
		} else {
			NGUIDebug.Log ("WWW error:" + www.error);
		}
	}

You have to make your path as URL-friendly,

Try this :

    IEnumerator Read (string path)
    {
      path = path.Replace(" ","%20");// this is extra line
       NGUIDebug.Log ("Reading: " + path);
       WWW www = new WWW (path);
       yield return www;
 
       if (www.isDone && www.error == null) {
                 NGUIDebug.Log ("WWW result:" + www.text);
          } else {
                   NGUIDebug.Log ("WWW error:" + www.error);
          }
     }

for more detail - More Information & Problems