capacitor-plugins
capacitor-plugins copied to clipboard
Local Notifications not working
Bug Report
Plugin(s)
@capacitor/local-notifications
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 4.7.0
@capacitor/core: 4.7.0
@capacitor/android: 4.7.0
@capacitor/ios: 4.7.0
Installed Dependencies:
@capacitor/android: 4.7.0
@capacitor/ios: 4.7.0
@capacitor/cli: 4.7.0
@capacitor/core: 4.7.0
Platform(s)
iOS and Android
Current Behavior
-
In iOS doesn't popup the notifications when in background nor during the app running.
-
On Android the notification starts the next day at the setted time...
Expected Behavior
to lunch the notification also when in background
Code Reproduction
async setNotification(_every: any, _hour: number, _min: number, _pill_name: string) {
await LocalNotifications.requestPermissions().then((res)=>console.log('perm status', res));
let randomId = Math.floor(Math.random() * 1000);
await LocalNotifications.schedule(<ScheduleOptions>{
notifications: [{
id: randomId,
title: "Pill Reminder",
body: "Remember to take " + _pill_name,
schedule: {
allowWhileIdle: true,
on: {hour: _hour, minute: _min},
every: _every,
repeats: true
}
}]
}).then( (res)=> console.log("status", res));
}
Other Technical Details
⚡️ To Native -> LocalNotifications requestPermissions 130233812
⚡️ TO JS undefined
⚡️ TO JS {"display":"granted"}
⚡️ To Native -> LocalNotifications schedule 130233813
⚡️ [log] - perm status {"display":"granted"}
⚡️ TO JS {"notifications":[{"id":417}]}
⚡️ [log] - status {"notifications":[{"id":417}]}
Additional Context
package.json
"dependencies": {
"@angular/common": "^15.2.0",
"@angular/core": "^15.2.0",
"@angular/forms": "^15.2.0",
"@angular/platform-browser": "^15.2.0",
"@angular/platform-browser-dynamic": "^15.2.0",
"@angular/router": "^15.2.0",
"@awesome-cordova-plugins/calendar": "^6.3.0",
"@awesome-cordova-plugins/core": "^6.3.0",
"@awesome-cordova-plugins/file-opener": "^6.3.0",
"@awesome-cordova-plugins/geolocation": "^6.3.0",
"@awesome-cordova-plugins/health": "^6.3.0",
"@awesome-cordova-plugins/native-geocoder": "^6.3.0",
"@capacitor-community/file-opener": "^1.0.4",
"@capacitor/android": "4.7.0",
"@capacitor/app": "4.1.1",
"@capacitor/core": "4.7.0",
"@capacitor/dialog": "^4.1.0",
"@capacitor/filesystem": "^4.1.4",
"@capacitor/haptics": "4.1.0",
"@capacitor/ios": "4.7.0",
"@capacitor/keyboard": "4.1.1",
"@capacitor/local-notifications": "^4.1.5",
"@capacitor/preferences": "^4.0.2",
"@capacitor/push-notifications": "^4.1.2",
"@capacitor/share": "^4.1.1",
"@capacitor/splash-screen": "^4.2.0",
"@capacitor/status-bar": "^4.1.1",
"@ckeditor/ckeditor5-build-classic": "^36.0.1",
"@fortawesome/angular-fontawesome": "^0.12.1",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-brands-svg-icons": "^6.3.0",
"@fortawesome/free-regular-svg-icons": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@ionic/angular": "^6.5.6",
"@teamhive/rich-text-editor": "^2.3.2",
"@tinymce/tinymce-angular": "^7.0.0",
"angular-ng-autocomplete": "^2.0.12",
"axios": "^1.3.4",
"capacitor-blob-writer": "^1.1.9",
"capacitor-email-composer": "^1.2.1",
"chart.js": "^4.2.1",
"chartjs-top-round-bar": "^1.0.1",
"cordova-plugin-badge": "github:katzer/cordova-plugin-badge",
"cordova-plugin-calendar": "^5.1.6",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-ionic": "5.5.3",
"form-data": "^4.0.0",
"ionicons": "^6.1.3",
"jetifier": "^2.0.0",
"jwt-decode": "^3.1.2",
"qs": "^6.11.0",
"rxjs": "^7.8.0",
"ts-md5": "^1.3.1",
"tslib": "^2.5.0",
"uninstall": "^0.0.0",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.2.0",
"@angular-eslint/builder": "^15.2.1",
"@angular-eslint/eslint-plugin": "^15.2.1",
"@angular-eslint/eslint-plugin-template": "^15.2.1",
"@angular-eslint/template-parser": "^15.2.1",
"@angular/cli": "^15.2.0",
"@angular/compiler": "^15.2.0",
"@angular/compiler-cli": "^15.2.0",
"@angular/language-service": "^15.2.0",
"@capacitor/cli": "4.7.0",
"@ionic/angular-toolkit": "^8.0.0",
"@ionic/lab": "3.2.15",
"@types/file-saver": "^2.0.5",
"@types/jasmine": "~4.3.1",
"@types/node": "^18.14.5",
"@types/pacote": "^11.1.5",
"@typescript-eslint/eslint-plugin": "5.53.0",
"@typescript-eslint/parser": "5.53.0",
"eslint": "^8.34.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "40.0.0",
"eslint-plugin-prefer-arrow": "1.2.3",
"jasmine-core": "~4.5.0",
"jasmine-spec-reporter": "~7.0.0",
"karma": "~6.4.1",
"karma-chrome-launcher": "~3.1.1",
"karma-coverage": "~2.2.0",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"ts-node": "~10.9.1",
"typescript": "~4.9.5"
},
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.
Please see the Contributing Guide for how to create a Code Reproduction.
Thanks! Ionitron 💙
granted you access to the app source code. will be public once finished
Please, can you provide a public sample app? it can be a reduced one. The whole team needs access to the sample apps, not just me.
ok, give me 5
https://github.com/pazDontExist/local-notification-bug
Some updates:
- On iOS still nothing
- On WEB the notifications are fired as soon as entered (doesn't wait the time specified)
- On Android the notification start becoming active at 24 hour later at the specified time...
Honestly..is all this a bug or my own stupidity ?
I haven't tested it on iOS but I can confirm the problem with WEB and Android. As soon as the every
parameter is defined then notification is scheduled 24 hours later. You can see it here:
if (every != null) {
Long everyInterval = schedule.getEveryInterval();
if (everyInterval != null) {
long startTime = new Date().getTime() + everyInterval;
alarmManager.setRepeating(AlarmManager.RTC, startTime, everyInterval, pendingIntent);
}
return;
}
So If you define day
as every
parameter, startTime
is now
+ 24 hours as a default. The question is how to schedule a repeating notification but not with 24 hours delay.