katzer / cordova-plugin-local-notifications

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

iOS - No notifications triggered if array length > N #1535

Closed voidbrain closed 6 years ago

voidbrain commented 6 years ago

I have Array of notifications, when I set them (and I see them when I query them with getAll() ) but notifications does not appear. The original length of the array was 60. It started working when I changed to 45.

Your Environment

Expected Behavior

trigger the notifications Tell us what should happen notifications should be triggered

Actual Behavior

notifications are not triggered (if length=60 no notification at all, if length=45 it works)

Tell us what happens instead

Steps to Reproduce

Reproduce this issue; include code to reproduce, if relevant

` for(let day in calendario){ let notification = { id: dayrow["id"], title: 'Calendario svuotamenti'+" "+(row["zona"]?row["zona"]:row["comune"]), text: 'Domani: ' + notificationText, at: new Date( notificationTimeDate.year(), notificationTimeDate.month(), notificationTimeDate.date(), notificationTimeDate.hour(), notificationTimeDate.minute(), ), }; this.notifications.push(notification); } this.notifications.sort((a, b) => a.at < b.at ? -1 : a.at > b.at ? 1 : 0) let maxNotificationsNumber = 45; // 60 is too much this.notifications = this.notifications.slice(0, maxNotificationsNumber);

if(this.platform.is('cordova')){ this.localNotifications.cancelAll().then(() => { this.localNotifications.schedule(this.notifications); this.notifications = []; }); } `

Context

What were you trying to do?

Debug logs

Include iOS / Android logs

katzer commented 6 years ago

iOS has some internal limits for how many notifications you can schedule.

voidbrain commented 6 years ago

yes but what is this (number, I suppose) limit? I remember there was a limit with older versions of iOS but for what I understand it had been removed time ago.

When I set notifications there is no feedback about the correct or failed set up and also I cannot see difference between a failed and a correct set up.

If I query the notifications list after the set up it is correct, also if N = 60 or more. So, why it is considered in some cases and not in others?

So how can I understand if notifications will work or not?

katzer commented 6 years ago

@voidbrain There's actually no way through the plugin to get immediate feedback if a notification could be scheduled because the way differs to much between different mobile platforms.

rwillett commented 6 years ago

We count the number of notifications we have scheduled to make sure we never get near the limit. Possibly easier for us as we don't schedule hundreds in advance. However we do check what we have scheduled and manage future notifications accordingly.

katzer commented 6 years ago

The limit for iOS is around 64 - there's no error if you schedule more. The system keeps the soonest-firing 64 notifications. However thats internal behaviour and not under control by the plugin.

I also wont ask why you're scheduling 45+ notifications in advance. You will know why however thats not favoured by iOS/Apple.

GitToTheHub commented 6 years ago

I had the same issue here. My coworker tested my app on a iOS Device and didn't get any notifications there. Finally (and with the help of that issue here), i resolved the problem as i maximum schedule now 64 Notifications and not more. If you schedule more than 64 Notifications, the Notifications will not work any longer.

@katzer

I used the following JS to avoid the problem:

// Warning for iOS, only the first 64 Notifications will be scheduled.
// see: https://developer.apple.com/documentation/uikit/uilocalnotification
if(notificationsData.length > 64) {
  console.warn("Under iOS, only the first 64 Notifications will be used, the rest will be discarded");
  // Shorten array to 64 elements
  notificationsData = notificationsData.slice(0, 64);
}
GitToTheHub commented 6 years ago

@katzer With my sample code i only wanted to indicate, that you could add a warning message for iOS, if the user schedules more than 64 Notifications. Because, the Notifications will not work anymore, if you schedule more than 64.

katzer commented 6 years ago

@GitToTheHub I will add a hint on the README however the limit is different for every OS and in case of Android for every manufacturer. Adding a runtime check slows down the code to much as the plugin need to load all notifications first before scheduling an additional one.

GitToTheHub commented 6 years ago

Ok, you are right, its very expensive to load all notifications first, to add then another notification. A hint in the readme would be really good :) You wrote, that there can be a limit on Android. I thought always, there is no limit for Notifications. These are news for me :)