Skip to main content
Participant
August 19, 2011
Question

cache jpgs in ios and retrieve them

  • August 19, 2011
  • 1 reply
  • 2101 views

This is for an iPad app and the user may or may not have an network connection.

Initially, I will have about 50 or so images that I need to download from a web server.

I want to cache them on the iPad.

I will check for new content when the app is opened everytime but if the user already has the latest images or they don't have a network connection, I want them to be able to use the cached images.

The check for new images part I have figured out. It's the caching and retrieving of cached images that I am not sure how to do. So...

How do I cache images on iOS and retrieve them if necessary?

Oh, I am using Flash CS5, (5.5 on the way).

Thanks.

This topic has been closed for replies.

1 reply

Participating Frequently
August 19, 2011

Use the File APIs. Pick a directory, either the ApplicationStorageDirectory or a temporary directory seem appropriate for your use. Download your images to this directory and instead of loading the images to display from the remote server, load them from your cache directory.

joda9731Author
Participant
August 19, 2011

Thanks Joe.

I can't find an example of how to download images from a web server and save them to the ApplicationStorageDirectory, retrieve them and display on stage.

Or some combination of examples.

Not that I need my code spoon-fed to me but I just never have used the File API.

Do you know of any such examples?

Participating Frequently
August 19, 2011

I would use URLLoader to download the files into a bytearray.

Create the file with the File class.

Use the FileStream class to write the byte array to the file.

There's a tutorial on the File API here: http://www.adobe.com/devnet/air/flex/quickstart/articles/xml_prefs.html

It talks about reading and writing an XML file. Saving an image is similar, but you would use writeBytes() not writeUTFBytes().

The URLLoader class is covered here: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cfd.html (although it looks like most of the examples are really more complicated than you need -- so if that doesn't make sense. let me know.)