iOS And XML Image Results Download in the Background?

John Patten johnpatten at mac.com
Wed Feb 22 19:42:59 EST 2012


Thanks Ken!

I went round and round with this, but I think I have it now.

I only had to make one change. That was value of idx was including the image url, so that it contained (2, http://theimageurl.jpg) I just asked it to put word 1 of idx into idx and that seemed to fix that issue. I also added a +1 to the end of the if idx<= statement as it was skipping the last URL in the list.

Thanks Again!

John Patten
SUSD

On Feb 22, 2012, at 2:34 PM, Ken Corey wrote:

> 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
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list