It is not working on iOS 11.2 or iPhoneX
See original GitHub issueConfig.xml
<plugin name="cordova-plugin-local-notification" spec="0.9.0-beta.2" />
Ionic info:
cli packages: (C:\Users\lok\AppData\Roaming\npm\node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : 7.0.1
local packages:
@ionic/app-scripts : 3.1.8
Cordova Platforms : none
Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 25.2.5
Node : v6.10.0
npm : 3.10.10
OS : Windows 8.1
Environment Variables:
ANDROID_HOME : C:\Program Files (x86)\Android\android-sdk
Misc:
backend : pro
I have installed the plugins like so:
ionic cordova plugin add cordova-plugin-local-notification
npm install --save @ionic-native/local-notifications
Code:
app.component.ts
constructor(){
this.platform.ready().then(() => {
timer(60000, 60000).subscribe(val => {//schedule Notification
const hours = moment().format("H");
const minutes = moment().format("m");
if (hours == '10' && minutes == '1') this.scheduleNotification();
});
this.localNotificationHandler();
});
}
scheduleNotification() {
forEach(this.authenticationProvider.member.projects, (project: Project) => {
forEach(project.transactions, (transaction: Transaction) => {
if (transaction.dueOn != null && moment(transaction.dueOn).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD')) {
const id = random(1, 1000);
cordova.plugins.notification.local.schedule({
id: id,
title: 'Due Today',
text: `Payment for ${transaction.category.name}: ${transaction.description} of ${Number(transaction.totalPrice).toLocaleString()} is due today.`,
data: { transaction: transaction, project: project },
trigger: { every: { hour: 10, minute: 1 } },
});
}
});
});
}
localNotificationHandler() {
this.localNotifications.on('click', (notification, state) => {
const data = notification.data;
const transaction = data.transaction;
const project = data.project;
this.goToEditTransaction(transaction, project);
});
}
It is working fine on the same day if an app goes to background mode few hours (less than 4 hours) on android device. But it is not working on iOS 11.2 or iPhoneX. On the Android device itself, we cannot trigger the click event. If we clicked the notification It opens the app again with a splash screen and goes to the desired screen (i.e. Edit ) without relevant data. That is useless since we need data for the edit screen.Could you tell me how to solve these issues?
Same sort of issue: https://forum.ionicframework.com/t/ionic-local-notification-trigger-call-back-is-not-working-when-app-is-in-background-for-a-while/114925
Issue Analytics
- State:
- Created 5 years ago
- Comments:17
Top GitHub Comments
Times do not work on the background on IOS. You cannot schedule a notification using a background timer as the moment the app goes in the background, the JavaScript timer stops.
The Xcode simulator does not emulate the real IOS OS and keeps background timers running.
As said before, strip your code back and start with something simple and work your way up to something complicated.
Rob
@ddralves @Sampath-Lokuge I am using IONIC 1 and I am having the same problem… I’m trying to generate local notifications in the background. they work on an iphone6 but on an iphone xr nothing happens. I’m testing them in a simulator.