Local notification not working when app is close


#1

Hi all ! Could anyone suggest please … I am use Cordova Local-Notification Plugin and the notification doesn’t appear again when the app was closed … Is there any solution ??

this.localNotifications.schedule({
  id: Math.floor(Math.random() * (1000000000 - 1) + 1),
  title: 'Mobile',
  text: 'Updating Complete!',
  sound: (this.platform.is('android') && this.settingsProvider.settings.sound == true) ? 'file://assets/sounds/android.mp3' : 'file://assets/sounds/android.mp3',
  badge: 1,
  icon: 'file://assets/icon/download.png',
  smallIcon: 'file://assets/icon/download.png'
});

#2

I apologize, the problem was not in the plugin.


#3

Hey I have the same problem. When i kill the app on android the notfication doesn’t appears. So I would like to know if you solved it?


#4

Hey, I am facing the same problem. How did you solve it?


#5

I got it .Thanks.If anyone else is facing the same issue, just try to declare this.localNotifications.on(‘click’, (success)=>{ alert(“clicked”) } on the landing/home page.


Ionic local notifications not working when app close
#6

How it will trigger ? will it trigger even app close ?


#7

Probably yes. If you see the provided code above the other user tells it fixed his problem to declare inside the landing/home page

this.localNotifications.on('click', (success) => { 
alert('clicked')
}

If you have further problems just let us know.


#8

No i am not getting any local notification when app close


#9

Can you provide your .ts file so I can check for you?


#10

import { Component } from ‘@angular/core’;
import { Platform } from ‘ionic-angular’;
import { StatusBar } from ‘@ionic-native/status-bar’;
import { SplashScreen } from ‘@ionic-native/splash-screen’;
import { LocalNotifications } from ‘@ionic-native/local-notifications’;

import { HomePage } from ‘…/pages/home/home’;
@Component({
templateUrl: ‘app.html’,
providers:[LocalNotifications]
})
export class MyApp {
rootPage:any = HomePage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private localNotifications: LocalNotifications) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
;
statusBar.styleDefault();
splashScreen.hide();
alert('Alert ')
this.localNotifications.schedule({
text: ‘Delayed ILocalNotification’,
every:‘minute’,
at: new Date(new Date().getTime() + 60000),
led: ‘FF0000’,
sound: null
});

 this.localNotifications.on('click', (success)=>{ alert("clicked") });
});

}
}


#11

declare this in your home/landing page:
this.localNotifications.on(‘click’, (success)=>{ alert(“clicked”) });
});
and see if it works.


#12

i was declared both in app.componnent.ts only


#13

Include it in your home.ts