Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by Tiago 1 · Jun 02, 2010 at 12:56 PM · iphonewwwsavefilestream

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

Hy,

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?

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
17
Best Answer

Answer by spinaljack · Jun 02, 2010 at 03:42 PM

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);
    cache.Close();
    Debug.Log("Cache saved: " + cachedAssetBundle);

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Julian-Glenn · Sep 25, 2010 at 12:31 AM 0
Share

Great info, just saved ma few hours work :)

avatar image bernardfrancois · May 17, 2011 at 08:54 AM 5
Share

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

avatar image bernardfrancois · May 17, 2011 at 08:55 AM 0
Share

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

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

avatar image BerggreenDK · Nov 05, 2012 at 09:22 PM 0
Share

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

avatar image
3

Answer by ZammyIsOnFire · May 07, 2015 at 09:15 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by unity fly · Dec 02, 2013 at 07:07 AM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rutter · Dec 02, 2013 at 07:08 AM 0
Share

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.

avatar image unity fly · Dec 02, 2013 at 07:50 AM 0
Share

thank you rutter. works fine !

avatar image
0

Answer by belly123456 · Jan 06, 2017 at 10:22 AM

Yep you can retrieve data by yourself. There are programs to do that. For example File Manager App For Iphone I used it few times.it's free and it works as good as can be expected. The main thing is to stop using the external hard disk until you use this tool, and avoid writing any files to it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Parse an online text file 1 Answer

save FileStream with www.movie doesn't work very well for Resources.load 0 Answers

Sending device info via WWW for Unity iPhone or Android 1 Answer

Which platforms support the "file://" protocol in the WWW class? 2 Answers

WWW Object Leaking? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges