Reputation: 59
I built a Phonegap App with this plugin, and it seems, as it is used in the app:
The config.xml :
<plugin spec="https://github.com/katzer/cordova-plugin-local-notifications.git#b8f358e" />
But when I try to send local notifications it looks like the plugin doesn't work. I tried this:
document.addEventListener('deviceready', function ()
{
alert(1);
cordova.plugins.notification.local.schedule({
id: 1,
title: 'Some Timer',
message: 'Some Message'
});
alert(2);
}, false);
But only the first alert
is working, that's why I think that the plugin isn't working right. So how can I build an App to send local notifications?
Thank you very much :-)
cordova -v 9.0.0 ([email protected])
cordova plugin ls cordova-plugin-whitelist 1.3.4 "Whitelist"
But as shown above, I added the local.notification plugin in the config.xml, and the Adobe Phonegap Build webpage, says that the plugin is used.
cordova platform ls Installed platforms: android 8.0.0 browser 4.1.0 Available platforms: electron ^1.0.0 ios ^5.0.0 osx ^5.0.0 windows ^7.0.0
PS: I posted a similar question two days ago, but I edited it to specify my question.
Upvotes: 0
Views: 5688
Reputation: 10237
Thanks for sharing the file. I was able to run successfully your app and the notifications works each time. However, you need to edit the code as below
For notifications without ID param
cordova.plugins.notification.local.schedule({
title: 'My first notification',
text: 'Thats pretty easy...',
foreground: true
});
For notifications with ID param, ID should be unique
cordova.plugins.notification.local.schedule([
{ id: 1, title: 'My Second notification' },
{ id: 2, title: 'My Third notification' }
]);
Index.js
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
onDeviceReady: function() {
this.receivedEvent('deviceready');
},
receivedEvent: function(id) {
oneNotification();
multipleNotification();
}
};
app.initialize();
function oneNotification() {
cordova.plugins.notification.local.schedule({
title: 'My first notification',
text: 'Thats pretty easy...',
foreground: true
});
}
function multipleNotification() {
cordova.plugins.notification.local.schedule([{
id: 1,
title: 'My Second notification'
},
{
id: 2,
title: 'My Third notification'
}
]);
}
Upvotes: 2