我在这里遇到了一个非常讨厌的问题 . 每次,我尝试在我的项目中使用文件和文件传输插件,我得到Uncaught TypeError:尝试使用 store = cordova.file.dataDirectory;
获取数据目录时无法读取未定义错误的属性'dataDirectory' . 现在,我've been trying to solve my problem for hours, but I couldn' t找到任何帮助 . 我'm also using the Barcode Scanner plugin in this project an it'的工作就像一个魅力 . 我正在使用PhoneGap 3.6.3和jQuery Mobile 1.4.4 . 因为我可能错过了一些重要的东西......
我在我的config.xml中包含了这样的插件:
<gap:plugin name="org.apache.cordova.file" version="1.3.1" />
<gap:plugin name="org.apache.cordova.file-transfer" version="0.4.6" />
也许这可能是一个提示:Windows Phone的PhoneGap Build日志确认正在添加插件 . 但似乎它们没有被添加到Android构建中,因为我在构建日志中找不到它们的任何引用 .
Windows Phone日志:
添加www \ plugins \ org.apache.cordova.file-transfer \ www \ FileTransfer.js添加www \ plugins \ org.apache.cordova.file-transfer \ www \ FileTransferError.js添加www \ plugins \ org.apache . cordova.file \ WWW \ File.js
这是我的index.js的一部分,不包括条形码扫描仪功能 .
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById('download').addEventListener('click', this.downloadFile, false);
document.getElementById('scan').addEventListener('click', this.scan, false);
document.getElementById('encode').addEventListener('click', this.encode, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
downloadFile: function(){
//The directory to store data
var store;
//Used for status updates
var $status;
//URL of our asset
var assetURL = "https://www.dropbox.com/s/d4s8mnkfwdqylns/test.txt?dl=0";
//File name of our important data file we didn't ship with the app
var fileName = "test.txt";
document.addEventListener("deviceready", init, false);
function init() {
$status = document.querySelector("#fileStatus");
$status.innerHTML = "Checking for file";
store = cordova.file.dataDirectory;
//Check for the file.
window.resolveLocalFileSystemURL(store + fileName, appStart, downloadAsset);
}
function downloadAsset() {
var fileTransfer = new FileTransfer();
console.log("About to start transfer");
fileTransfer.download(assetURL, store + fileName,
function(entry) {
console.log("Success!");
appStart();
},
function(err) {
console.log("Error");
console.dir(err);
});
}
function appStart() {
$status.innerHTML = "Datei aktuell";
}
},
// [...Functions for Barcode scanner...]
};
我还在index.html中包含了phonegap.js文件:
<body>
...
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
我真的希望有人能帮我解决问题 .
1 回答
我一直认为你需要先打电话
对于cordova.file东西来定义并能够调用resolveLocalFileSystemURL .
所以在你的情况下,尝试这个修改