我从 Intel XDK NEW 开始,我的应用程序需要从我的服务器下载一些 PDF 文件。
我遵循了 API 示例(http://software.intel.com/en-us/node/492847)。“更新”功能有效并显示进度,但“完成”功能永远不会触发,文件永远不会被存储。
“更新”功能:
function cacheUpdated(evt) {
var outString = "";
outString += "current bytes downloaded: " + evt.current;
outString += " total bytes in download: " + evt.total;
var percentage = evt.current/evt.total
outString += " percentage downloaded: " + percentage + "%";
outString += " the unique id is: " + evt.id ;
outString += "the URL is: " + evt.url;
console.log(outString);
}
“完整”功能:
function cacheComplete(evt) {
var outString = "";
outString += "The procedure succeeded (" + evt.success + ") ";
outString += " the unique id is: " + evt.id ;
outString += "the URL is: " + evt.url;
alert(outString);
}
并开始下载:
function downloadFile() {
intel.xdk.cache.addToMediaCacheExt("http://192.168.1.101/apostilas/57/1/apostila1.pdf",
Math.random()*100000);
document.addEventListener("intel.xdk.cache.media.update", cacheUpdated, false);
document.addEventListener("intel.xdk.cache.media.add", cacheComplete, false);
}
难道我做错了什么?
编辑:问题出在模拟器上;这在设备上运行良好。