Before updating to Windows 10 you may need to return your Pro license. More information here

Unity iPhone: Can I store data on the iPhone to be used later?


I would like to save data on the iPhone that is going to be send (at a defined time) to another device. Can I do that?


more ▼

asked Jun 02, 2010 at 12:56 PM

avatar image

Tiago 1
118 7 7 12

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

From the unity iphone manual:

You can save required files to a Documents folder next to your game's Data folder.

public static string GetiPhoneDocumentsPath () 
                // Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents 
                // Application.dataPath returns              
                // /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data 
                // Strip "/Data" from path 
                string path = Application.dataPath.Substring (0, Application.dataPath.Length - 5); 
                // Strip application name 
                path = path.Substring(0, path.LastIndexOf('/'));  
                return path + "/Documents"; 

You can Cache downloaded asset bundle using .NET file API and for reuse it in the future by loading it via WWW class

    // Code designed for caching on iPhone, cachedAssetBundle path must be different when running in Editor
    // See code snippet above for getting the path to your Documents folder
    private var cachedAssetBundle : "path to your Documents folder" + "/savedassetbundle.assetbundle"; 
    var cache = new System.IO.FileStream(cachedAssetBundle, System.IO.FileMode.Create);
    cache.Write(download.bytes, 0, download.bytes.Length);
    Debug.Log("Cache saved: " + cachedAssetBundle);

In short, yes you can save files on the iphone with the System.IO.FileStream

more ▼

answered Jun 02, 2010 at 03:42 PM

avatar image

10.2k 28 74 133

Great info, just saved ma few hours work :)

Sep 25, 2010 at 12:31 AM Julian Glenn

Since Unity3.3, Application.persistentDatapath can be used, removing the need to edit the Application.dataPath string. More can be read here.

May 17, 2011 at 08:54 AM bernardfrancois

More can be read here: http://www.previewlabs.com/file-io-in-unity3d/

(apparently html-style hyperlinks don't work in the comments here)

May 17, 2011 at 08:55 AM bernardfrancois

If you place a "Using" statement in the beginning/top of your .net/mono files you can remove the long paths eg. System.IO.FileStream can be shortned to FileStream

Nov 05, 2012 at 09:22 PM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

how can i delete saved data which i stored at persistent data path from the application ? can anyone suggest ?

more ▼

answered Dec 02, 2013 at 07:07 AM

avatar image

unity fly
16 2 897 10

Do you know the file's location? If you placed a file at a path like Path.Combine(Application.persistentDataPath, "myFile"), you could also check File.Exists() with that path, or call File.Delete() with that path to remove the file.

Dec 02, 2013 at 07:08 AM rutter

thank you rutter. works fine !

Dec 02, 2013 at 07:50 AM unity fly
(comments are locked)
10|3000 characters needed characters left

The API you want to use to get path to Documents folder of an App (where things can be persistently stored) is Application.persistentDataPath.

more ▼

answered May 07 at 09:15 AM

avatar image

26 2 3

(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



Answers and Comments



asked: Jun 02, 2010 at 12:56 PM

Seen: 29678 times

Last Updated: May 07 at 09:15 AM