Skip to main content
Known Participant
June 19, 2015
Answered

writing to an included folder in air for ios build?

  • June 19, 2015
  • 2 replies
  • 857 views

Hi there, Im just creating a cached offline version of my app.  I am including a folder in the build called ASSETS now when I load from an asset from a server I want to place it into the included folder.  I have tried numerous path combinations but to no avail? Can I just check that if this is actually possible?

Many thanks

Phil

This topic has been closed for replies.
Correct answer kheftel

‌if I could add my assets folder into the documents directory that would be perfect but I don't think that is possible?  I maybe wrong and if anyone has any suggestions that would be great also.

thanks

phil


no, the documents directory doesn't exist until the app is installed - it's basically like apps on the windows desktop that make their own subdirectories inside My Documents.  All the directories in your IPA, including assets, live in the application directory after installation, kind of like an app's install directory in Program Files on the windows desktop.

There is a static File.applicationDirectory property on the File class, it points to the application directory, but it also notes the following:

Modifying content in the application directory is a bad practice, for security reasons, and is blocked by the operating system on some platforms.

I would manually build the shipping assets in the Assets directory before building the IPA, and then when your application downloads new content from the server, put it in the cache directory (available through <code>File.cacheDirectory</code>.

When you load content and there's no network, first check in the cache directory, if the file is not then load from the Assets directory.  Yes, you're storing two copies but there's really no other choice on iOS.

2 replies

User Unknow
Legend
June 19, 2015

Your application folder is limited by iOS Sandbox. Instead use Documents folder (using appropriate File class API). I don't suggest to use Cache folder because iOS can delete files without any notification.

kheftel
Inspiring
June 19, 2015

I don't suggest to use Cache folder because iOS can delete files without any notification.

Using the cache folder for things that can be re-downloaded or re-created by the app follows Apple guidelines.  The documents folder is supposed to be for user-generated content.  Not following their guidelines could lead to being rejected by the app store.

Specifically from the page I linked:

Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory

Data that can be downloaded again or regenerated should be stored in the <Application_Home>/Library/Cachesdirectory.

Known Participant
June 19, 2015

‌thanks for the info guys just to shed some more light on my issue:  the app is a framework at the moment and rolls out with no content (blank) as the user views sections I save a cached version if they are offline in the future.  My major concern is that unless each section is viewed whilst having a connection when they go offline the sections that have not been visited will appear blank.  What I was trying to do is use the caching sequence pre submission to build my offline cache that I can bundle with the submission ipa.  The if they never go online they already have a cached version.

My thinking was then to use the asset folder I include with the ipa build to overwrite newer assets when they are online and available.  That would need me to be able to save into the included folder in the app submission.  Otherwise I could end up with a massively bloated version of my app that has my pre cached content and also any newly cached content once in use.

Again thanks for the responses and guidance on this issue.

kheftel
Inspiring
June 19, 2015

this should help: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html

Make sure you follow Apple's guidelines about where to put downloaded files tho, sounds like they should go in the caches directory:

iOS Data Storage Guidelines - Apple Developer

I can't remember off top of head if writing to the app's directory is supported or not in iOS, but a better plan would probably be to download it to the caches directory, and then on startup, check to see if the files are there via the File object's <code>exists</code> property, and if they don't exist locally, re-download them.  This will follow Apple's guidelines and allow the system to purge your cache if needed when disk space becomes low.

Known Participant
June 19, 2015

‌also just to clarify that the app is querying a db that will be constantly updated and can contain 1000's of calls/assets.  So if I was to check on load of what has changed it would require automation of those 1000's of queries that would be a real pain.