iOS And XML Image Results Download in the Background?

Ken Corey ken at kencorey.com
Tue Feb 21 07:20:22 EST 2012


Sure, why not?  Let's assume that this is all kicked off from a button 
press:

-- I assume you have your URLs in a list

on mouseUp
   -- send in 0 milliseconds means call downloadImage as soon
   --   as this handler is done
   -- I'd create placeholder graphics where the images might
   --   go once downloaded, and then you can put them into a list
   send "downloadImage 1" to me in 0 milliseconds
end openCard

on downloadImage idx
   -- check to see if we've fallen off the end of the list.
   if idx <= the number of lines of listOfURLs then
     get URL "http://blah.com/image.gif"
     -- do something terribly clever to display them to the user.
     -- e.g. replace the placeholder images above for item idx
     --
     -- queue up the next image for download
     send "downloadImage "&(idx+1) to me in 0 milliseconds
   end if
end downloadImage

So, your app interface should be happily trundling along responding to 
user input, while the images are being downloaded.  Increase the '0 
milliseconds' for more responsiveness.

This assumes you want the images to come down one at a time.  You 
/could/ queue up more than one at a time by sending 'downloadImage' to 
yourself multiple times, but then you'd have to get fancier managing the 
index.

You probably don't want to issue all the sends at the same time, because 
unless you have a monster fat pipe none of them will come down at any 
rational rate of speed.

You might also want to think about caching the image somehow.  Check for 
its existance before the get, and avoid hitting the net at all. (Of 
course, that means you have to let the user clear the cache, limit the 
size to which it grows, etc.)

-Ken



On 19/02/2012 05:40, johnpatten at me.com wrote:
> I'm looking to use the Flickr API search routine to return the latest
> images for a specific tag. I will probably limit it to the 10 or 20 most
> recent images. I can create the resulting URL to the images from the
> resulting XML, and set the file name of an image to that URL, looping
> through the list of images, but I'm curious as to what would be best
> practice would be to download these images in the background? Ideally I
> would like the user to be able to use the simulated swipe routines
> between the images.
>
> The only thing I can think of is downloading the images in the
> background as soon as the iOS app is launched. Could a script like this
> be launched at openStack and run in the background?




More information about the use-livecode mailing list