Skip to main content
Participant
June 9, 2014
Question

Can't save file on iOS device with low free space available

  • June 9, 2014
  • 1 reply
  • 471 views

Hi,

I was using SharedObject to save settings in my game. However, recently I discovered on one of our devices it doesn't work. I've found somewhere on this forum discussion that air can't save sharedobject when available space is lower than about 300mb (link here: Bug#3711301 - sharedobjects fail when available storage is low). On my iphone it's about 40mb, but file, which I want to save is just 2 variables.. persistenceManager doesn't work too (well i've looked at source and it's just using SharedObject). So i've decided to just write file by myself:

declarations:

public var mute:Boolean = false;

public static var fullId:String = "";

then in constructor:

flash.net.registerClassAlias("Settings", GameSettings);

load();

and finally save() and load() functions:

public function save():void

  {

  try {

  log("begin save()");

  var file:File = File.applicationStorageDirectory.resolvePath("settings.txt");

  var stream:FileStream = new FileStream();

  stream.open(file, FileMode.WRITE);

  var settings:GameSettings = new GameSettings();

  settings.fullId = fullId;

  settings.mute = mute;

  stream.writeObject(settings);

  stream.close();

  log("end save()");

  }

  catch (error:Error) {

  log("[ERROR] " + error.name + ": " + error.message + "\n" + error.getStackTrace());

  }

  }

  public function load():void

  {

  try {

  log("begin load()");

  var file:File = File.applicationStorageDirectory.resolvePath("settings.txt");

  if(!file.exists){

  log("settings.txt does not exist, created new one..");

  save();

  return;

  }

  var stream:FileStream = new FileStream();

  stream.open(file, FileMode.READ);

  var settings:GameSettings = stream.readObject() as GameSettings;

  mute = settings.mute;

  fullId = settings.fullId;

  log("loaded mute = " + mute);

  log("loaded fullId = " + fullId);

  stream.close();

  log("end load()");

  }

  catch (error:Error) {

  log("[ERROR] " + error.name + ": " + error.message + "\n" + error.getStackTrace());

  }

  }

My GameSettings class:

package

{

  public class GameSettings

  {

  public var fullId:String;

  public var mute:Boolean;

  public function GameSettings()

  {

  }

  }

}

This works on desktop, android. Works on my ipad too, which has 10gb of free space. However, like I said, it doesn't work on iphone5s with 40mb free memory.

Here's a log:

begin load()

settings.txt does not exist, created new one..

[ERROR] Error: Error #0

     at Autumn/save()

     at Autumn/load()

     at Autumn()

It's clear that AIR can't open or write to 'settings.txt' file. What can I do to solve that issue (other than making more free space on iphone)? Is there any workaround for that?

This topic has been closed for replies.

1 reply

rosmediaAuthor
Participant
June 16, 2014

Any help please?