pg-plugin-screen-orientation
pg-plugin-screen-orientation copied to clipboard
PhoneGap.exec not defined error
Hello,
I am using your plugin with phonegap and Cordova.
I followed your instructions and am getting an error with the .js file at line 4, PhoneGap.exec is not defined.
Could you please advise what the problem could be? Has this feature been depreciated in Cordova?
Thanks
I also tried changing this to Cordova.exec and same error.
The plugin should work with Cordova.
From the error message, I guess that probably you have not imported cordova.js.
Do you import cordova.js in your html by doing as follows?
Thank you for the reply.
Yes I have Cordova installed. I am using a fully functioning Cordova app. The app will not work once I install your plugin. I am also testing this directly onto a device, no virtual machine. Have you tested this new version in a development environment yet ? I spent hours trying to get this plugin to work with no success.
Perhaps you have a fully working demo?
Thank you.
I am also having this issue both on a virtual android device and directly on a Galaxy Nexus that I am using to test my app. I am using cordova version 1.9.0 and I am importing it before the screen orientation plugin.
The error being reported is as follows...
07-10 18:30:24.118: E/Web Console(6437): Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/pg-plugin-screen-orientation.js:4
The same error message appears for me also. The problem isn't the fact that I have misplaced files, because I can successfully deploy the landscape mode in for one on my views (the problem then being that every view after that is in landscape). So to fix this I tried to add for the next view portrait mode and ended up having a non working application with the mentioned error message.
08-09 12:44:02.300: D/CordovaLog(26237): file:///android_asset/www/lib/pg-plugin-screen-orientation.js: Line 4 : Uncaught TypeError: Object #<Object> has no method 'exec'
in the js file I tried both
cordova.exec(null, null, "ScreenOrientation", "set", [str]); and
PhoneGap.exec(success, fail, "ScreenOrientation", "set", [str]);
as possible solutions, but still crashing
Ha. Found a workaround. The problem was that if the orientation change is fired too early, (for me the first view) it blows up the whole application. For me the fix was that I needed the landscape in a view that is deployed much later, so the fix was:
the view that needs to be landscape
navigator.screenOrientation.set('landscape');
window.weHaveChangedOrientation = true;
and then in the first view
if (window.weHaveChangedOrientation) {
navigator.screenOrientation.set('portrait');
}
so only force portrait if landscape has been forced earlier.
and remember to listen to the
document.addEventListener("deviceready", function(){ whatever }, false);
to avoid problems I had :P