Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

writing to an included folder in air for ios build?

Explorer ,
Jun 19, 2015 Jun 19, 2015

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

TOPICS
Development
823
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jun 19, 2015 Jun 19, 2015

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 follo

...
Translate
Engaged ,
Jun 19, 2015 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2015 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 19, 2015 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 19, 2015 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2015 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2015 Jun 19, 2015

‌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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 19, 2015 Jun 19, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2015 Jun 19, 2015

‌thanks for the clarification! This is what I was expecting but also hoped would not be the case! I suppose when I have updated items cached I could in theory remove the original items (compile in the ipa) so it doesnt get too hefty that way I can keep only one complete version on the device etc

thanks a lot for the great explanation!

phil

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 19, 2015 Jun 19, 2015

sure thing! All this stuff can get pretty complex!

Also, I didn't mention of course that when you have network, you can check with the server to see if there's new content, and if so, download it and replace the copy in the cache folder.

If I've answered your question, would you mind marking my answer correct?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2015 Jun 19, 2015
LATEST

marked as correct answer! Again thanks again for the info

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines