Skip to main content
Participant
June 27, 2013
Question

iOS - Where to save files so they remain after app updates

  • June 27, 2013
  • 4 replies
  • 3843 views

Hi,

I'm developing a game and I save the state to a file as recommended in this article:

http://www.adobe.com/devnet/flash/articles/saving_state_air_apps.html

Which saves it here:

var f:File = File.applicationStorageDirectory.resolvePath("myApp.dat");


Everytime I compile the app gets uninstalled and the file is deleted. My concern is what happens when I release an update through the app store. Will the player data get lost? Where's the best place to save the player data so it doesnt get lost?

Other areas could be:

File.applicationDirectory

File.cacheDirectory

File.desktopDirectory

File.documentsDirectory

File.userDirectory

Has anyone had experience with this?

This topic has been closed for replies.

4 replies

Clandesdyne
Participating Frequently
March 11, 2014

I know this is an older thread, but I wanted to share what I typically use when I'm saving data to a device.

public var file: File = File.userDirectory; //retains the information from the previous install.

OR

public var file: File = File.applicationStorageDirectory; //Overwrites when the user updates their app.

Make sure to add these variables:

public var filestream: FileStream = new FileStream();

public var appDataTemp: String;

Then you just need to add a function that saves the data.  I like to make mine a string that I later split based on some unique seperator.

public function saveData() {

            try {

                filestream.open(file, FileMode.WRITE);

                filestream.writeUTF(score+ "&&&" + currentLevel + "&&&" + username );

                filestream.close();

                debug_text.text = score+ "&&&" + currentLevel + "&&&" + username ;

            } catch (error: Error) {

                trace("update failed");

            }

}

Here's where you would read the data:

public function readData() {

                try {

                    file = file.resolvePath("myTextFileName.txt");

                    filestream.open(file, FileMode.UPDATE);

                    appDataTemp = filestream.readUTF();

                    var pulledData = appDataTemp.split("&&&");

                    score = int(pulledData[0]);

                    currentLevel = int(pulledData[1]);

                    username = pulledData[2];

                    debug_text.text = "LOADED: " + appDataTemp;

                } catch (error: Error) {

                    //Testing on PC

                    trace("ERROR: no myTextFileName.txt");

                    score = 0;

                    currentLevel = 1;

                    username = "";

                }

                filestream.close();

}

Participant
March 12, 2014

I was a bit worried then when you said:

public var file: File = File.applicationStorageDirectory; //Overwrites when the user updates their app.

So I have just tested saving a file in File.applicationStorageDirectory

I then went to TestFlight and installed an older version of my game. When it loaded the saved file was still there in tact, nothing was lost.

This means you can safely save to the applicationStorageDirectory and you won't lose anything when releasing new updates.

However, if you delete the app then the files will get deleted or if you are compiling and installing the app from your IDE, that will also delete the existing files as it uninstalls the app first.

markc888
Inspiring
September 24, 2013

Any files saved to File.documentsDirectory will not be deleted when your app is updated via the App Store.

This behaviour doesn't apply though when you are re-installing the app via your IDE, say Flash CC for example but you should be able to test if using TestFlight. www.testflightapp.com

i.e. download v1.0.0 of your app from Testflight and run your app (files will be created and saved). Save some new data or settings to the file.

Then create a v1.0.1 and download that from Testflight. This should install the new app but leave the documents directory intact.

You could also test applicationstoragedirectory to see if the same behaviour applies.

When your app is launched it's important to test to see if the files exists before trying to create new ones.

NB. File.documentsDirectory should only be used to store data that cannot be easily redownloaded from a web server as this directory is backed up to iCloud (if available).

Mark.fromOP
Inspiring
June 27, 2013

I use the SharedObjects class which stores data as long as the user has the app installed, when updated it keeps the data but if uninstalled and reinstalled all data is wiped. The way AIR installs apps on test machines is not like an App Store update but more like an uninstall and reinstall so its not a good simulator. However this issues only exists on iOS on android overwriting an installed app keeps the shared objects in tact.

Adobe Employee
June 27, 2013

Could you please share the steps you are using to update the application.

Regards,

Nimit

Participant
June 27, 2013

There is no process in place, I'm just curious how it works. Without uploading different versions to the app store I can't test what happens and that's not a simple process.

When developing in FDT the app gets uninstalled and reinstalled each time I compile. I presume this is different from the update process? Does an update from the appstore leave the files in the Application Storage Directory automatically?

Inspiring
August 19, 2013

For my app I install a file in the applicationstoragedirectory that is default settings if there isn't one already. As my users establish there own settings the file is updated. Now when an app update occurs there are instruction that if that file is present then not install the file or else it just overwrites it.