我无法让 cordova 文件系统工作。我有一个具有以下依赖项的项目:
com.ionic.keyboard 1.0.3 "Keyboard"
org.apache.cordova.console 0.2.12 "Console"
org.apache.cordova.device 0.2.13 "Device"
org.apache.cordova.file 1.3.2 "File"
org.apache.cordova.file-transfer 0.4.8 "File Transfer"
在app.js
中,我定义了对 Controller 模块的依赖:
angular.module('starter', ['ionic', 'controllers']);
Controller 代码基本上是这样的:
angular.module('controllers', [])
.controller('GalleryCtrl', function ($scope) {
function success() {...}
function error() {...}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error);
}
}
然后我得到的是:
LocalFileSystem is not defined
此外,requestFileSystem
未定义。造成这种行为的原因是什么?
我正在使用 cordova 4.1.2 和 ionic 1.3.1。
编辑:这是相应的 html 标记:
<body ng-app="starter" ng-controller="GalleryCtrl">
<ion-nav-view>
<ion-slide-box id="slideBox">
<ion-slide ng-repeat="..."> <!-- details omitted -->
</ion-slide>
</ion-slide-box>
</ion-nav-view>
</body>
最佳答案
您根本没有等待 deviceReady 事件被触发,因此文件插件尚未加载。改变
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error);
到
document.addEventListener("deviceready", function() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error);
}, false);
即使在那之后,LocalFileSystem.PERSISTENT 也可能是未定义的(对于我来说,在模拟等时),但它可以用 1 替换,因为它只是一个常量.
关于Cordova:本地文件系统未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27985512/