Schedule number of Local Notifications

瘦欲@ 提交于 2019-11-27 01:28:29

问题


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?


回答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.




回答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



回答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.




回答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.




回答5:


I found this Swift library which is doing almost the same thing that we are looking for. I am going to try this and will confirm how it works:

https://github.com/ahmedabadie/ABNScheduler




回答6:


Apple Doc says:

An app can have only a limited number of scheduled notifications; the system keeps the soonest-firing 64 notifications (with automatically rescheduled notifications counting as a single notification) and discards the rest.



来源:https://stackoverflow.com/questions/7721362/schedule-number-of-local-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!