Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule number of Local Notifications

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?

like image 274
Minkle Garg Avatar asked Oct 11 '11 04:10

Minkle Garg


2 Answers

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
like image 197
EmptyStack Avatar answered Nov 02 '22 08:11

EmptyStack


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.

like image 36
JakubKnejzlik Avatar answered Nov 02 '22 09:11

JakubKnejzlik