Can't get cordova.file.dataDirectory working, am I missing something?

2,183 views
Skip to first unread message

James Anderson

unread,
Mar 17, 2015, 5:30:28 PM3/17/15
to phon...@googlegroups.com
I only needing this to work on iOS, running on the new iPad mini 3

var dataDirectory = cordova.file.dataDirectory;

The above line is giving me the following error:
undefined is not an object (evaluating 'cordova.file.dataDirectory')

I am new to PhoneGap, so it's very possible I'm missing an important step in the build. Here's the steps I have followed:
-download the sample build from PhoneGap website (i.e. folder with .cordova, hooks, platforms, plugins, www, and config.xml)
-make sure config.xml contains <gap:plugin name="org.apache.cordova.file" /> and <gap:plugin name="org.apache.cordova.file-transfer"/>
-www/cordova.js doesn't exist, but I've read that's okay because this gets included when you build the app (have tried downloading the latest cordova.js and placing it in this folder, made no difference)
-zip the package & upload it on build.phonegap.com
-download the .ipa, setup page with download link, run app (which works properly, I'm able to download and run the app on my iPad)

deviceOnReady is firing properly, I'm just at a stand still with the error message mentioned above.

Am I missing some important part of the build? Do I need to use command line or am I okay to do it this way through build.phonegap.com?


Thank you,
Jamie

Kevin Grabher

unread,
Mar 18, 2015, 11:14:48 AM3/18/15
to phon...@googlegroups.com
Have you tried building your project locally?
Are you doing dataDirectory = cordova.file.dataDirectory in the deviceready function like this:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    dataDirectory = cordova.file.dataDirectory
}

James Anderson

unread,
Mar 23, 2015, 11:34:31 AM3/23/15
to phon...@googlegroups.com
I've tried initializing on deviceready like you mentioned, but am still getting the same error. I'm wondering if cordova.js is even being included properly.

You mention building the project locally - does this mean with node/CLI command line instead of using build.phonegap.com? So far I've only built it using build.phonegap.com, is it possible this is what's creating the issue?

Thanks

James Anderson

unread,
Mar 23, 2015, 2:48:36 PM3/23/15
to phon...@googlegroups.com
Quick follow- up: Using command line now, I noticed as soon as I include the org.apache.cordova.file plugin, the deviceready not firing occurs. Any reason why this plugin would cause such a problem?

Kevin Grabher

unread,
Mar 24, 2015, 11:01:38 AM3/24/15
to phon...@googlegroups.com
I don't have any experience with phonegap as I only build with cordova locally. Have you tried re-adding the plugin (plugin rm, plugin add), eventually even removing and adding the platform?
Reply all
Reply to author
Forward
0 new messages