Schedule number of Local Notifications

10,824

Solution 1

I've created app with local notifications and in this case user was notified every 20/40/60 minutes in given time interval (eg. 8:00-20:00). The solution was to generate up to 64 notification through whole day and set repeatInterval of UILocalNotification to NSCalendarUnitDay. Of course if you need to use more sophisticated notification pattern, this is not the way to go.

Also It's worth to mention, that since iOS7 I had to, due to client requirements, implement rescheduling of notifications in background app refresh.

Solution 2

As you are already aware, you can schedule maximum of 64 notifications per app. If you add more than that, the system will keep the soonest firing 64 notifications and will discard the other.

One way to make sure all notifications get scheduled is to schedule the first 64 notifications first, and then on regular time intervals (may be on every launch of the app or each time a notification fires) check for the number of notifications scheduled and if there are less than 64 notifications, lets say n notifications, then schedule the next (64 - n) notifications.

int n = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
int x = 64 - n;
// Schedule the next 'x' notifications

Solution 3

Basic solution to this is using repeatInterval for notifications occurring at specific intervals. This will reduce the number of redundant notifications. But still if the number exceeds 64 then you can employ one strategy to use userInfo dictionary and pass the next notification's time and message in it and schedule it when the - (void) application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification method is called. This can be a bit tricky so you've to be careful that proper data is passed in the userInfo dictionary and notifications are set accurately. I hope this helps.

Solution 4

I don't know of any other way than to schedule the first 64 notifications first, then at the launching, backgrounding and launching of a notifications, check if the number of notifications is least than 64 if it is then reschedule your notifications.

I don't get why Apple implementation of notifications is sooo lame. If anyone can figure a better way let me know.

Share:
10,824
Minkle Garg
Author by

Minkle Garg

iOS Developer

Updated on June 04, 2022

Comments

  • Minkle Garg
    Minkle Garg about 2 years

    I am making an iPhone application in which I have implemented the concept of local notification to alert the user for taking medicine.

    But in iOS we can't schedule more than 64 notifications at a time. But I have a number of date-time entries in the database. How could I schedule more than 64 notifications?