AIR App Compliance with Apple Data Storage Guidelines

Update in AIR 3.6: PreventBackup Property introduced for File Objects. More Details here.

AIR applications targeted for iOS may get rejected in the application review process with the reason “Rejection: 2.23 Apps must follow the iOS Data Storage Guidelines or they will be rejected“. Usage of File.applicationStorageDirectory or Local Shared Objects (LSOs) in the application might be the reason. Recently, Apple has updated the Data Storage Guidelines with the release of iOS 5. Since the guidelines are accessible only to registered iOS developers, let me summarize the key points below:-

  • The entire home directory is backed up to iCloud by default, except the Application bundle itself, Caches directory and the tmp directory.
  • In order to minimize the data that needs to be backed up, Apple expects the developer to adhere to the following guidelines:
    • Only user generated data, which other wise cannot be recreated like an image capture or voice recording should be stored in Documents directory.
    • Application Support Directory must be used to store only application specific data files. For example:- application configuration files or game levels. Data stored here is not vulnerable to be purged under low memory conditions.
    • Data that can be regenerated such as downloadable content should be stored only in Caches directory. Caches directory must be used to store application specific files that can be re-created easily. iOS may take the liberty to delete this directory occasionally when the device is low on memory space. Hence, critical application data must never be stored here, since it faces a risk to be purged under low memory conditions.
    • Temporary data should be stored in tmp directory. All application specific files that need not persist between application launches must be put here and should be deleted at application exit. 

AIR developers, too, must adhere to these guidelines while developing apps targeted for iOS platform and align the files created by their application accordingly. AIR maps File.applicationStorageDirectory and Local Shared Objects (LSOs) inside “Application Support Directory” . Since this directory is backed up on iCloud by default, one must use it only to store application data files that must not be deleted under low memory conditions. LSOs must also be used on iOS to store critical application specific data only, such as current game state.

Since there is no direct property to access the Caches and tmp directory in AIR, let me discuss a workaround if one faces a need to use these directories. Instead of using the static directory paths populated by File class properties, one can create global File objects that point to the corresponding directories and finally write to any file inside those directories. Sample code snippet can be found below.

public var cacheDir:File = null;
public var tempDir:File = null;

//Initialize the Objects with proper paths.
var str:String = File.applicationDirectory.nativePath;
cacheDir= new File(str +"/\.\./Library/Caches");
tempDir = new File(str +"/\.\./tmp");
var fr:FileStream = new FileStream();
fr.open(cacheDir.resolvePath("myCache.txt"),FileMode.WRITE); fr.writeUTFBytes("works");
fr.close();

More details on how to make app backups more efficient on iOS platform can be found here.

19 Responses to AIR App Compliance with Apple Data Storage Guidelines

  1. turntable says:

    This does not work – FileStream.open fails. Tested on iPhone 4, iOS 5.1.1, Flash Builder 4.6, AIR 3.3.

  2. I can confirm this, calling the open method does not work. Using openAsync does work. For both iPhone 4 and 3GS. FDT 5.5, AIR 3.2

    Best,
    Sidney

  3. Varun Bhatia says:

    This is a known issue when you package ipa-app-store and ipa-adhoc targets. We are investigating this and hope to get it fixed asap.

  4. Pingback: air stuff | åkesson's blog

  5. Jack says:

    My AIR app utilizes a SQLite database. The app makes a backup copy of this database and keeps it updated with any changes that are done in the app. It is able to be restored if the user needs it. Where should this backup SQLite database be stored on iOS?

    Thanks.

    • Varun Bhatia says:

      Since its a backup copy and can be regenerated, hence such downloadable content should be stored only in Caches directory.

      • Jack says:

        Thanks for the reply. If it is stored in the Caches directory, is it going to get deleted under low memory conditions? If so, this would make the backup file pointless, and probably shouldn’t be stored here?

  6. Rafal says:

    Video files stored in the Library/Caches don’t work with StageVideo – NetStream returns FileNotFound. However when stored in applicationStorage, they work as expected.

    Do you have any ideas why it’s not working?

  7. Pingback: AIR App Compliance with Apple Data Storage Guidelines | TechnoVeille

  8. Pingback: Geolocation issues with AIR on iOS (with a fix!) « QueTwo's Blog

  9. Pingback: Geolocation issues with AIR on iOS (with a fix!) | TechnoVeille

  10. ClaudioNW says:

    HI,
    I do not understand why we should use the lines hereafter to access the temporary folder:
    var str:String = File.applicationDirectory.nativePath;
    tempDir = new File(str +”/\.\./tmp”);

    It seems that you can rather use the class File.
    File.createTempDirectory().resolvePath(your filename);
    Your app should not be rejected. Of course this folder is not backed up to the cloud and you have to remove the folder as soon as the app exits.

    Any comments?

  11. neha says:

    With the latest AIR 3.6 prerelease, a new static property, File.cacheDirectory has been introduced, which directly points to the /Library/Caches directory on iOS.
    Details at: http://labsdownload.adobe.com/pub/labs/flashruntimes/shared/air3-6_flashplayer11-6_releasenotes.pdf

  12. Sergi Kolesnik (@SergiKoles) says:

    It actually doesn’t make clearer what to do if I want to save user’s current settings. It is stated that Shared Objects are stored in Application Support Directory which is saved at iCloud.

    What if user doesn’t sync to iCloud before uninstall app? What if user doesn’t have iCloud setup at all?

    Is the only sure way to save app settings in the documents directory? Or user directory?

  13. Andrew says:

    re: Jack et al

    What was the final solution for storing a backup SQLite or other backup files?

    For that matter, where should images/videos be stored where they will Not be deleted under low memory conditions?

  14. Pier Bover says:

    I’m using applicationStorageDirectory to store files. The problem is those files get deleted when the user updates his app…

    I’m using ad-hoc distribution and compiling with Air 3.6.

    What do I have to do have persistence after updating the app?