katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.75k forks source link

iOS - what to use instead of trigger.after ? #1864

Open ScottWaring opened 4 years ago

ScottWaring commented 4 years ago

The trigger.after feature works for Android, pushing the notifications only after the time if the key exists. Since trigger.after doesn't exist for iOS, notifications fire in iOS when they aren't needed.

What is the way to achieve the behavior of trigger.after in iOS?

MY Environment

package.json: "@ionic-native/local-notifications": "^5.0.0",

Ionic: Ionic CLI : 5.4.13 Ionic Framework : @ionic/angular 4.11.0 @angular-devkit/build-angular : 0.801.3 @angular-devkit/schematics : 8.1.3 @angular/cli : 8.1.3 @ionic/angular-toolkit : 2.0.0

Cordova: Cordova CLI : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : ios 5.0.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.5.3, (and 21 other plugins)

Utility: cordova-res : 0.8.1 native-run : not installed

System: NodeJS : v10.15.1 npm : 6.13.4 OS : macOS Mojave

HOW IM BUILDING NOTIFICATIONS:

let notification: ILocalNotification = {
           id: id,
            title: 'SOME TITLE',
            text: 'TEXT',
            trigger: {
                every: {
                    hour: scheduledTime.hours(),
                    minute: scheduledTime.minutes()
                }
            },
            foreground: true,
            data: {task: task},
};

if the user has completed the 'task' then the notification is updated this way:

 notification.trigger.after = new Date(new Date().setHours(23, 59, 0, 0));

Expected Behavior

Notifications should not fire before after date time.

Actual Behavior

Android behaves as expected: notifications cease to fire before after date time. iOS does not behave as expected: notifications continue to fire before after date time.

bjanaszek commented 3 years ago

@ScottWaring This isn't an issue with the plugin, but rather a limitation introduced by Apple with the new local notification framework. The only real workaround is to convert the repeating notification to a series of individual notifications based on the trigger schedule. This is less-than-ideal for a number of reasons, but if you need to be able schedule a repeating notification in the future, I'm not sure there's another solution.