iOS And XML Image Results Download in the Background?

Ken Corey ken at kencorey.com
Wed Feb 22 17:34:43 EST 2012


On 22/02/2012 22:21, John Patten wrote:
> I've tried both Ken and Gerry's suggestions for downloading images in the background via a URL.
> I attempted to combine both Ken and Gerry's examples, in order to prevent the error messages I was receiving in Ken's first example. However, it is not working...yet.

I think the problem is that "libUrlDownloadToFile" downloads a file 
asynchronously.  That is to say that it doesn't hang about and wait for 
the transfer to happen.  Therefore you get all of your image downloading 
requested at the same time!

If you put a callbackMessage after libUrlDownloadToFile, it will get 
called when the download is finished:

on mouseUp
     send "downloadImage 1" to me in 0 milliseconds
end mouseUp

on downloadImage idx
   if idx<= the number of lines in cd fld "imageURLs" then
     set the itemDel to tab
     put item 1 of line idx of cd fld "imageURLs" into tURL
     set the itemDel to "/"
     put the last item of tURL into tImagename
     put specialfolderpath("Documents")&"/WhaleImages/" before tImagename

     libUrlDownloadToFile tURL, tImagename, "downloadComplete "&(idx+1)
   end if
end downloadImage

on downloadComplete idx
     send "downloadImage "&idx to me in 0 milliseconds
end downloadComplete

That way, you only have a single download happening at any one time again.

-Ken




More information about the use-livecode mailing list