ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
518 stars 583 forks source link

LocalNotification: Scheduled Notifications are not delivered if the app has been closed for more than 2 hours #1718

Closed alexandruvilcea closed 1 year ago

alexandruvilcea commented 1 year ago

Bug Report

Plugin(s)

@capacitor/local-notifications@4.1.4

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 5.2.2
  @capacitor/core: 5.2.2
  @capacitor/android: 5.2.2
  @capacitor/ios: 5.2.2

Installed Dependencies:

  @capacitor/cli: 5.2.2
  @capacitor/core: 5.2.2
  @capacitor/android: 5.2.2
  @capacitor/ios: 5.2.2

Platform(s)

Android

Current Behavior

I’m having issues with Local Notifications on Android. (All Android devices, and all versions of android). I’ve scheduled multiple notifications to trigger several times throughout the day, but the notifications are only delivered for a period of 2 hours after the app is closed. After the 2 hours have passed, the notifications are not delivered anymore. Notifications will always fire immediately after enter the app, or (which is even stranger) they will fire immediately after I plug in the charger. This is happening only on android, it never happened on iOS. Before closing the app, I always verify the pending notifications array and all notifications are there. And with every notification I’m scheduling, I am setting allowWhileIdle: true.

I’ve followed all the documentation here: Local Notifications Capacitor Plugin API | Capacitor Documentation

This is all on Capacitor 4 (Android SDK 32), and the plugin version is 4.1.4. I even tried with with Capacitor 5.

Any help would be appreciated with this. Thanks!

PS: The app is for scheduling tasks and sometimes I can have up to 4 notifications in an hour, rarely I schedule two notifications at the same time.

Expected Behavior

The app should be sending all notifications at the time they are scheduled, just as it happens on iOS, regardless of the time the app has been closed.

Code Reproduction

    await LocalNotifications.schedule({
      notifications: [
          {
              id: 1,
              title: `${task.name} will start now`,
              body: `{task.name} will start now`,
              schedule: {
                at: task.date,
                allowWhileIdle: true,
              },
              extra: {
                task: JSON.stringify(task),
              },
            },
        ],
   });
Ionitron commented 1 year ago

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks! Ionitron 💙

Ionitron commented 1 year ago

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day! Ionitron 💙

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.