x


How to download a file and store it on a tablet

Hi everyone,

I have a huge problem. I am currently working on a game on iPad2 and Android tablets. I need to download a file (an xml file, to be precise) from an url address, and store it on the device for later use (reading, parsing, whatever).

I have read that I could use persistentDataPath -- which I have done (as shown below) -- but this doesn't work for the iPad, while being perfectly ok for the Android tablet. Here is a snippet of my code:

WWW www = new WWW("INSERT URL HERE");
yield return www;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(www.text);
if (iPhoneSettings.generation == iPhoneGeneration.iPad2Gen){
  xmlDoc.Save(Application.persistentDataPath + "/database.xml");
}
else if(Application.platform == RuntimePlatform.Android){
  xmlDoc.Save(Application.persistentDataPath + "/database.xml");
}
else{ // for PC applications
  xmlDoc.Save(Application.dataPath + "/StreamingAssets/database.xml");
}

I really can't see what's wrong with this.

Thank you in advance!

Bye.

EDIT: Just added a missing line in the code. Can anyone help me? :)

more ▼

asked May 25 '12 at 06:39 PM

Jobaby gravatar image

Jobaby
15 1 1 3

did you ever solve this one?

Oct 24 '12 at 09:54 AM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

here's a fragment for a PNG, it may help you ...

function _folder():String
    {
    return Application.persistentDataPath + "/fattie";
    }
function _filename( n:int ):String
    {
    return "picture" + n + ".png";
    }
function _fullFilename( n:int ):String
    {
    return _folder() + "/" + _filename(n);
    }

    var bytes:byte[];
    bytes = sillyPhoto.EncodeToPNG();
    System.IO.File.WriteAllBytes( _fullFilename( 13 ), bytes );
more ▼

answered Oct 24 '12 at 11:27 AM

Fattie gravatar image

Fattie
20.1k 60 92 153

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x263
x249

asked: May 25 '12 at 06:39 PM

Seen: 883 times

Last Updated: Oct 24 '12 at 11:27 AM