Reputation: 130
I am using PhoneGap Developer App to test my app during development. But I can't get the plugins to start working. In this case I am using the notification. JavaScript alert works but notification.alert is not working. Please I have been going around this for days now. Here is what my code looks like.
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/responsive.js"></script>
<script type="text/javascript">
app.initialize();
if(window.localStorage.getItem('session') == null){
navigator.notification.alert("Not logged in", null, "Login?", "Continue");
navigator.notification.beep(1);
navigator.notification.vibrate(1000);
//alert('not logged in');
}else{
navigator.notification.alert("Logged in", null, "Login?", "Continue");
navigator.notification.beep(1);
navigator.notification.vibrate(1000);
//alert('logged in');
}
</script>
Upvotes: 0
Views: 98
Reputation:
@ITECH-PLANET,
if you are using the standard example that comes with the PhoneGap Developer App, then you MUST wait until the deviceready
has *fired*.
You can test this by putting function section of code in a function, then calling that function.
Like this:
app.notify : function () {
if(window.localStorage.getItem('session') == null){
navigator.notification.alert("Not logged in", null, "Login?", "Continue");
navigator.notification.beep(1);
navigator.notification.vibrate(1000);
//alert('not logged in');
}else{
navigator.notification.alert("Logged in", null, "Login?", "Continue");
navigator.notification.beep(1);
navigator.notification.vibrate(1000);
//alert('logged in');
}
}
Then change to this:
<script type="text/javascript">
app.initialize();
app.notify();
</script>
For additional details read #4 of Top Mistakes by Developers new to Cordova/Phonegap
Upvotes: 1