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();
More details on how to make app backups more efficient on iOS platform can be found here.