cordova-plugin-local-notifications icon indicating copy to clipboard operation
cordova-plugin-local-notifications copied to clipboard

Extra messages on the first of the month?

Open mnowak-umich opened this issue 6 years ago • 5 comments

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.

Your Environment

  • Plugin version: 0.9.2
  • Platform: iOS
  • OS version: 10, 11 and 12
  • Device manufacturer / model: iPhone 7
  • Cordova version (cordova -v): 8.0.0
  • Cordova platform version (cordova platform ls): ios 4.5.4
  • Plugin config
  • Ionic Version (if using Ionic)

I'm not sure if this is a bug or something else but I am scheduling 18 messages at specific times over the course of 55 days. For some reason, I get multiple messages (2 extra) when the scheduled message happens to fall on the first of the month. It happened on October 1 and today on November 1. Has anyone seen anything like this?

mnowak-umich avatar Nov 01 '18 19:11 mnowak-umich

I haven’t. But I also haven’t looked for it. Did not happen to me on Nov 1 so I don’t believe it’s affecting me... perhaps you could post your scheduling code? On Nov 1, 2018, 12:16 PM -0700, mnowak-umich [email protected], wrote:

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN! Provide a general summary of the issue. Your Environment

• Plugin version: 0.9.2 • Platform: iOS • OS version: 10, 11 and 12 • Device manufacturer / model: iPhone 7 • Cordova version (cordova -v): 8.0.0 • Cordova platform version (cordova platform ls): ios 4.5.4 • Plugin config • Ionic Version (if using Ionic)

I'm not sure if this is a bug or something else but I am scheduling 18 messages at specific times over the course of 55 days. For some reason, I get multiple messages (2 extra) when the scheduled message happens to fall on the first of the month. It happened on October 1 and today on November 1. Has anyone seen anything like this? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Tawpie avatar Nov 03 '18 16:11 Tawpie

The code is a little complicated but here is the nut of it. scheduleValueNotifications() goes thru a list of days and computes the date to deliver the message for each date in the sequence. loadValueNotifications() loads a local JSON file with the message content. Since it loads async, it calls finishScheduleValueNotification when it completes and that's where the actually creation of the notification occurs.

function scheduleValueNotification(id, date) { loadValueMessages(finishScheduleValueNotification, id, date); }

function reasonForNotificationID(notificationID) { var reasons = getReasons(); var item = notificationID - VALUE_NOTIFICATION_ID_START; var reasonIndex = item % reasons.length; var itemIndex = Math.floor(item / reasons.length) % MESSAGES_PER_REASON;

return reasons[reasonIndex] + (itemIndex + 1); // Something like Faith1

}

function finishScheduleValueNotification(id, date) {

var now = new Date();
var reasonForID = reasonForNotificationID(id);
var valueNotificationInfo = valueMessages[reasonForID];

var notificationDetails = {
    title: 'Some encouragement to improve your heart health',
    text: valueNotificationInfo.message,
    id: id,
    foreground: false
};

if (date != undefined) {
	notificationDetails.trigger = { at: date };
}
else {
	notificationDetails.trigger = { at: now };
}

cordova.plugins.notification.local.schedule(notificationDetails);

}

function scheduleValueNotifications() { for (var index = 0; index < VALUE_NOTIFICATION_DAYS.length; ++index) { var day = VALUE_NOTIFICATION_DAYS[index]; var date = dateTimeAtDayIndex(day, VALUE_HOUR, VALUE_MINUTE);

	scheduleValueNotification(VALUE_NOTIFICATION_ID_START + index, date);
}

}

mnowak-umich avatar Nov 05 '18 15:11 mnowak-umich

The first thing I would try is instead of scheduling the notifications one at a time in a for loop, schedule an array of notifications. That means you'll need to change scheduleValueNotification to create an array with each notification (including the trigger) and when array creation is complete then schedule the entire array in one swell foop.

I don't have a sound technical reason for this suggestion other than I had many difficulties getting a batch of notifications scheduled properly when trying to do them one at a time and have had no problems at all scheduling an array. My best guess is that the OS does what it does and if you happen to try to schedule another notification while the OS is processing a previous one, someone gets confused.

Tawpie avatar Nov 05 '18 15:11 Tawpie

Thanks for that suggestion! I will give it a try.

mnowak-umich avatar Nov 05 '18 15:11 mnowak-umich

Hi did you manage to solve this problem? I have the same situation... Some notifications arrive on the first day of the month, even though they were already shown in the previous month and should no longer pop up

ironfrol avatar Apr 01 '21 11:04 ironfrol