cordova-plugin-local-notifications icon indicating copy to clipboard operation
cordova-plugin-local-notifications copied to clipboard

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

Open Matsuo32 opened this issue 6 years ago • 15 comments

Your Environment

  • Plugin version:
  • Platform: ios
  • OS version:13.0
  • Device manufacturer / model: Apple
  • Cordova version :9.0.0
  • Cordova platform version : ios 5.0.1, android 8.1.0
  • Ionic Version :5.4.1

Expected Behavior

Local notifications trigger or click when app is closed or killed

Actual Behavior

Local notifications showed but it's not trigger or click when app is closed or killed, it just work only app open or run background

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();
  })

Matsuo32 avatar Sep 25 '19 07:09 Matsuo32

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

code4macaques avatar Sep 25 '19 17:09 code4macaques

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

katzer avatar Sep 26 '19 10:09 katzer

I am using ionic and capacitor and having the same issue

2-towns avatar Oct 07 '19 10:10 2-towns

I was misusing skipLocalNotificationReady. It's working now

2-towns avatar Oct 07 '19 10:10 2-towns

@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.

ravi-pandit14 avatar Oct 23 '19 11:10 ravi-pandit14

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

2-towns avatar Oct 24 '19 02:10 2-towns

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

LuanNg avatar Oct 31 '19 19:10 LuanNg

@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.

ravi-pandit14 avatar Nov 02 '19 12:11 ravi-pandit14

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

prteekagni avatar Jan 09 '20 11:01 prteekagni

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

StefanRein avatar Jul 11 '20 01:07 StefanRein

@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)

Guy-Sela avatar Jul 16 '20 12:07 Guy-Sela

@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.

StefanRein avatar Jul 16 '20 12:07 StefanRein

I was misusing skipLocalNotificationReady. It's working now

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

vvsatpute avatar Oct 01 '20 09:10 vvsatpute

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

StefanRein avatar Oct 01 '20 10:10 StefanRein

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?

bevinGithub avatar Feb 03 '23 12:02 bevinGithub