use*_*773 5 javascript apache ios cordova
我已经在我开发的应用程序上使用 Cordova(带有 iOS)一段时间了。我过去能够很好地访问文件系统。
我通过命令行界面安装了带有 Node 的 cordova 3.3.0 并添加了我需要的所有插件(几乎所有插件 - 当然包括文件)
当我列出插件时,我得到: Michaels-MacBook-Pro:hello michael$ cordova plugin ls
[ 'org.apache.cordova.battery-status',
'org.apache.cordova.console',
'org.apache.cordova.device-motion',
'org.apache.cordova.device-orientation',
'org.apache.cordova.dialogs',
'org.apache.cordova.file',
etc....']
Run Code Online (Sandbox Code Playgroud)
但是,我尝试运行以下测试代码:请注意,该代码位于index.js文件内,该文件在index.html中被正确引用
Index.html参考:
script type="text/javascript" src="cordova.js"
script type="text/javascript" src="js/index.js"
Run Code Online (Sandbox Code Playgroud)
索引.js:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("ready");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 5*1024*1024, gotFS, fail);
}
function gotFS(fileSystem) {
alert("got fs");
alert(fileSystem.root.fullPath);
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试警报(window.requestFileSystem),我得到的只是“准备好”;我变得不确定。
请有人帮我解决这个问题吗?我认为没有理由它不起作用。
任何帮助将非常感激!
亲切的问候,
迈克尔·麦克唐纳德
如果您正在 Chrome 中测试您的应用程序,您可能必须第一次运行此命令以在文件系统上保留一些空间:
// Request Quota (only for File System API)
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) {
console.log('Error', e);
});
Run Code Online (Sandbox Code Playgroud)
更多信息请访问https://developers.google.com/chrome/whitepapers/storage
我不确定这个解决方案是否适合您的情况,因为您说您的应用程序过去可以工作,但请尝试一下。