Reputation: 21
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?
Upvotes: 1
Views: 79
Reputation: 21
I tried changing the addEventListener statement by adding parentheses following onDeviceReady, which now calls the function onDeviceReady function, instead of just referring to the function, as follows:
document.addEventListener("deviceready", onDeviceReady(), false);
However, I realized this calls the function before the deviceready event is satisfied. So, I am still trying to find out why device ready is not firing.
Upvotes: 1