Joh*_*Ace 4 javascript ios cordova
我正在尝试将存储在phonegap文件夹(www/default_files/file.txt)中的文件复制到iOS中的文档文件夹,到目前为止我得到的是:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys)
{
fileSys.root.getFile("file.txt", null, function(theFile){ // file exist don't do anything},
function(error)
{
// file does not exist, so copy it
fileSys.copyTo(fileSys.root.fullPath, "www/default_files/file.txt",
function success(entry)
{
console.log("Success: " + entry);
},
function error(entry)
{
console.log(entry);
});
});
}, fileError);
Run Code Online (Sandbox Code Playgroud)
fileSys.root.fullPath包含正确的Documents Path,问题是如何访问www文件夹...
有任何想法吗?
这段代码适用于iOS.此函数将数据库文件的副本从/ www文件夹实现到/ Documents文件夹.
function copyBase(){
var wwwPath = window.location.pathname;
var basePath = 'file://'+ wwwPath.substring(0,wwwPath.length-10);
window.resolveLocalFileSystemURL(basePath+'myDB.db',
function(fileDB){
console.log('success! database was found')
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null);
function onSuccess(fileSystem) {
var documentsPath = fileSystem.root;
fileDB.copyTo(documentsPath, 'myDB.db',
function(){
console.log('copying was successful')
},
function(){
console.log('unsuccessful copying')
});
}
},
function(){
console.log('failure! database was not found')
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2578 次 |
| 最近记录: |