David
David

Reputation: 1674

Cordova Local Notifications Events not Working

I have been trying to get local notifications working on an Ionic 1 iOS app. I've installed the local notification plugin, and I can schedule notifications, but the callbacks don't seem to fire.

I can schedule a notification and it displays properly when the app is in the background:

cordova.plugins.notification.local.schedule({
    text: "Delayed Notification",
    at: new Date(new Date().getTime() + 5*1000)
});

But events never fire:

cordova.plugins.notification.local.on("click", function(notification) {
    alert("clicked: " + notification.id);
});

Upvotes: 0

Views: 686

Answers (2)

Gotts
Gotts

Reputation: 2424

I had similar issues.

Not sure if this is a bad idea but I had to put my trigger callback in appmodule and then it worked.

    //Trigger to monitor notifications in case they need to be cleared
    localNotifications.on("trigger", (notification, state) => {
          console.log("Triggering notification (App Module)",notification);            
    });

Upvotes: 0

ltayef s
ltayef s

Reputation: 1

cordova.plugins.notification.local.schedule({
    //add the Id of notification
    id: 1,
    text: "Delayed Notification",
    at: new Date(new Date().getTime() + 5*1000)
});

Upvotes: 0

Related Questions