gpt4 book ai didi

android - 使用 Phonegap/jQuery Mobile Android 和 iOS 应用程序下载文件并将其存储在本地

转载 作者:IT王子 更新时间:2023-10-28 23:53:37 25 4
gpt4 key购买 nike

我编写了一个 jQuery Mobile 应用程序,并用 Phonegap 将它打包到 iOS 和 Android 应用程序中。

此时我正在使用本地存储的 json 文件来读取数据。

我想不时通过从服务器下载更新的 json 文件来更新这些 json 文件。

如何从服务器获取json并将json文件存储到Android和iOS的本地文件系统中?

干杯乔赫

最佳答案

使用FileTransfer.download,这里是一个例子:

function downloadFile(){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry) {
var sPath = fileEntry.fullPath.replace("dummy.html","");
var fileTransfer = new FileTransfer();
fileEntry.remove();

fileTransfer.download(
"http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
sPath + "theFile.pdf",
function(theFile) {
console.log("download complete: " + theFile.toURI());
showLink(theFile.toURI());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
}
);
}, fail);
}, fail);
};
}

关于android - 使用 Phonegap/jQuery Mobile Android 和 iOS 应用程序下载文件并将其存储在本地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6417055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com