I'm very happy with livecode tsNet new library, it's way faster than libURl and livecode GET, POST...
So I've written a code to download a list of files using tsNetGetFile, it's working well on desktop and dictionary says that "tsNetGetFile" is for android and iOS too, BUT!!! I can't get it to work in mobile.
Please help to figure out this.
See the code.
Regards,
Gurgen
Code: Select all
######################################################
# TS DONWLOAD
######################################################
local sDownloadList
local tsDownload
-------------------------------------------------------------------------------
# downloadList
# pList: the list of files to download
# pSettings: An array contains download info
# pSettings["callbackobjectid"] : the object id to send callback
# pSettings["savepath"] : the file path to save files in
# pSettings["url"] : server URL, finishing with slash
# pSettings["maxonce"] : the maximum number of files to download at once
# CHANGES
# 09/22/2016: created
--------------------------------------------------------------------------------
command downloadList pList, pSettings
-- Save to local variables
put pList into sDownloadList
put 0 into tsDownload["index"]
put pSettings["callbackobjectid"] into tsDownload["callbackobjectid"]
put pSettings["savepath"] into tsDownload["savepath"]
put pSettings["url"] into tsDownload["url"]
put pSettings["maxonce"] into tsDownload["maxonce"]
put 1 into tsDownload["startline"]
-- Start download
downloadGroup
end downloadList
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
# downloadGroup
# CHANGES
# 09/22/2016: created
--------------------------------------------------------------------------------
command downloadGroup
-- Loop to download files at once
repeat with tFile = 1 to tsDownload["maxonce"]
put (tFile + tsDownload["startline"] - 1) into tLine
put line tLine of sDownloadList into sMedia
-- Download using TS
put tsNetGetFile(tFile, (tsDownload["savepath"] & sMedia), (tsDownload["url"] & sMedia),,"downloadComplate") into tResult
-- Save the download result
if tResult is empty then
put "ok" into tsDownload["files"][sMedia]
else
put tResult into tsDownload["files"][sMedia]
end if
end repeat
end downloadGroup
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
# downloadComplate
# pID: the id of connection
# CHANGES
# 09/22/2016: created
--------------------------------------------------------------------------------
command downloadComplate pID
add 1 to tsDownload["index"]
-- Close connection
tsNetCloseConn pID
-- Group done
if tsDownload["index"] mod tsDownload["maxonce"] = 0 then
-- Send a callback with downloaded files info
dispatch "downloadComplate" to tsDownload["callbackobjectid"] with tsDownload["files"]
-- Set do not backup for android
if the platform is "iPhone" then
repeat for each key tMedia in tsDownload["files"]
iphoneSetDoNotBackupFile (tsDownload["savepath"] & tMedia)
end repeat
end if
-- Reset
put empty into tsDownload["files"]
-- Download is finished
if tsDownload["index"] > the number of lines of sDownloadList then
dispatch "downloadFinished" to tsDownload["callbackobjectid"]
exit downloadComplate
end if
-- Go to next file group
add tsDownload["maxonce"] to tsDownload["startline"]
-- Download
downloadGroup
end if
end downloadComplate
################################################################