Local-notifications-in-cordova

Hello,

I am new to mobile development. I have downloaded sample code from github. https://github.com/qnimate/ReminderApp. I am not able to get the plugin “cordova.plugins.notification” to register. I would appreciate any assistance. By the way I am using Phonegap.

The script stops here.
cordova.plugins.notification.local.hasPermission(function(granted){
if(granted == true)
{
alert(‘granted’)
schedule(id, title, message, schedule_time);
}
else
{
alert(‘Notgranted’)
cordova.plugins.notification.local.registerPermission(function(granted) {
if(granted == true)
{
schedule(id, title, message, schedule_time);
}
else
{
navigator.notification.alert(“Reminder cannot be added because app doesn’t have permission”);
}
});
}
});

Hi there,

Is the plugin installed using cordova plugin add and is that script inside the ‘deviceready’ event?

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    // Now safe to use device APIs
}

If you’re unable to debug the javascript error you can alert to see which object is missing:

alert(cordova);
alert(cordova.plugins);
alert(cordova.plugins.notification);

etc.

When I add the alerts I get the following;
object Object
undefined
I assume that the plugin must not be installed. I have attempted to install the cordova plugin. Any suggestions?

You should have a plugins directory with “cordova-plugin-local-notifications” inside if it’s installed, if not run

cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications

You’ll also need to move your script into the onDeviceReady function I posted.

Some of our articles might help you - http://www.sitepoint.com/?s=notifications

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.