Trying to access the file system in a basic Meteor app with Cordova plugin.
Setup as follows:
Create project command: meteor create file2
Added Cordova plugin, command: meteor add cordova:[email protected]
However, document.addEventListener("deviceready", onDeviceReady, false); is not firing.
The Javascript console displays: Issuing deviceready from Meteor.startup
Here is my code in main.js:
function onDeviceReady() {
// Now safe to use device APIs
console.log('deviceready completed');
getPFile();
}
Meteor.startup(function() {
console.log('Issuing deviceready from Meteor.startup');
document.addEventListener("deviceready", onDeviceReady, false);
});
function getPFile() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {
console.log("fileEntry is file?" + fileEntry.isFile.toString());
writeFile(fileEntry, null);
}, onErrorCreateFile);
}, onErrorLoadFs);
}
I also tried inserting:
<script type="text/javascript" charset="utf-8" src="cordova.js">
</script>
in main.html, but JavaScript console then shows error
SyntaxError: Unexpected token '<'
in Cordova.js
Can anyone suggest a solution?