Skip to main content
Inspiring
February 1, 2013
Question

applicationStorageDirectory files not loading on iOS

  • February 1, 2013
  • 1 reply
  • 849 views

Hi All,

I'm building a game and I have a persistance manager class that manages loading/saving my players game state to the File.applicationStorageDirectory.

I am able to save my player's game to the applicationStorageDirectory, but when I try to load the game state, File.exists always returns false when I run the game on an iOS device. This issue only occurs on iOS - running on a PC is fine.

I've tried compiling with AIR3.4, 3.5 and 3.6 and all of them seem to have the same issue with iOS.

I've inspected the file system of the iOS device, and I can see that saving data to the applicationStorageDirectory is working fine.

Here's a summary of my code:

private var _gameSaveFilePath:String = "gamesave.dat";  

//THIS PART WORKS// 
public function save(serializableObject:ISerializable):void
{
var nativePath:String = File.applicationStorageDirectory.nativePath.toString();
var file:File = new File(nativePath + "/" + _gameSaveFilePath);

if (file.exists)
file.deleteFile();

var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeObject(serializableObject);
Logger.info(this, "save", "Saved GameState to file: " + file.nativePath);

fileStream.close();
}

//THIS PART RETURNS AN EMPTY FILE ON iOS, EVEN AFTER A SUCCESSFUL SAVE // 
private function getGameSaveFile():File
{
return File.applicationStorageDirectory.resolvePath(_gameSaveFilePath);
}

Can anyone please help with this issue? Why would File.applicationStorageDirectory.resolvePath fail only on iOS, when I know for sure that the file exists on the device?

This topic has been closed for replies.

1 reply

Inspiring
February 1, 2013

Hi All,

To cut a long story short, my problem turned out to be due to the Event.Exiting event (which triggered my save method) not being called on iOS, which is a known issue, but I wasn't aware of this.

So my game was barely ever saving - only maybe 1 out of every 10 times, and mostly not at all.

I'm not auto-saving every 30s and everything is working fine.