katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

Local notifications not trigger or click when app is closed or killed #1836

Closed Matsuo32 closed 2 weeks ago

Matsuo32 commented 5 years ago

Your Environment

Context

 (<any>window).skipLocalNotificationReady = true;
    this.platform.ready().then(() => {
    this.backgroundMode.enable();
    this.localNotifications.on('click').subscribe(res => {
        alert("click notification")
      });
      this.localNotifications.on('trigger').subscribe(res => {
        alert("trigger notification")
      });
      this.localNotifications.fireQueuedEvents();
    })
code4macaques commented 5 years ago

I have the same problem, please anyone who could help us?

katzer commented 5 years ago

I dont use Ionic, not sure if this is the reason. I tested it with latest versions and it works.

2-towns commented 5 years ago

I am using ionic and capacitor and having the same issue

2-towns commented 5 years ago

I was misusing skipLocalNotificationReady. It's working now

ravi-pandit14 commented 4 years ago

@arnaud-zad Have you tested this on Android as well? If so, are you able to access data in cordova.plugins.notification.local.on("trigger", (res) => {console.log(res); localStorage.setItem("notification","--notification trigger in kill state--")} if you kill app?

If notifications are working fine for you, it would be really helpful if you could provide a sample code or public repo.

2-towns commented 4 years ago

@ravi-pandit14 Yes I tried on Android. I didn't try to access data

LuanNg commented 4 years ago

it works on ios 13 and android 9 , i used this way to repeating notifications. let notification = { id: 1, data: {}, launch: true, title: "Test", text: "Test...", silent: false, trigger: { every: { hour: 0, minute: 0 } }, foreground: true, wakeup: true };

and please careful with conflict plugins such as cordova-plugin-fcm, cordova-plugin-background-geolocation, ... just remove them

ravi-pandit14 commented 4 years ago

@LuanNg if you kill/swipe the app from background then are you able to access data of on("trigger" function? If notifications are working fine for you, it would be really helpful if you could provide a sample code (with description) or public repo.

prteekagni commented 4 years ago

When the app is killed the notification gets trigger but onclick method doesn't work. Please suggest some solution

StefanRein commented 4 years ago

https://github.com/katzer/cordova-plugin-local-notifications/issues/1798#issuecomment-656962391

Guy-Sela commented 4 years ago

@StefanRein @katzer

Just making sure that I'm not missing anything... 'trigger' event will not fire when app is killed, no matter what. The only solutions are workarounds, not getting it to work somehow.

(Using Cordova and building for Android at the moment)

StefanRein commented 4 years ago

@Guy-Sela I tested on iOS. But to answer simply your question: Yes the trigger event (the click will if correctly setup) will NOT fire afterwards by launching or anything - only if you had the app in foreground.

At least in my test application where I thought I could depend on this. I could not. Also wrote in my answer how you could do this yourself. For me I had to schedule notifications for 3 days and also needed to have 2 queues. The ones which are to be fired and the ones which should be fired. There is a limit of 64 local notifications which can be scheduled.

vvsatpute commented 4 years ago

I was misusing skipLocalNotificationReady. It's working now

Exactly what did you change? Did you make it false?

StefanRein commented 4 years ago

@vvsatpute read my post about this / how to use this: https://github.com/katzer/cordova-plugin-local-notifications/issues/1798#issuecomment-656962391

bevinGithub commented 1 year ago

The notifications will not trigger when app is closed(killed) and will be triggered after opening the app #1895

Hi Stefan just a follow up does the event onTrigger works if the app is in the background or when device is locked?