本地通知的附表数量
我正在制作一个 iPhone 应用程序,其中实现了本地通知的概念,以提醒用户吃药。
但在 iOS 中,我们一次无法安排超过 64 个通知。但我的数据库中有许多日期时间条目。如何安排超过 64 条通知?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如您所知,每个应用程序最多可以安排 64 条通知。如果您添加的数量超过此数量,系统将保留最早触发的 64 个通知,并丢弃其他通知。
确保安排所有通知的一种方法是首先安排前 64 个通知,然后定期(可能在每次启动应用程序或每次触发通知时)检查安排的通知数量以及是否有少于 64 个通知,假设 n 个通知,然后安排下一个 (64 - n) 个通知。
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.
我创建了带有本地通知的应用程序,在本例中,用户在给定时间间隔(例如 8:00-20:00)内每 20/40/60 分钟就会收到通知。解决方案是全天生成最多 64 个通知,并将 UILocalNotification 的 repeatInterval 设置为 NSCalendarUnitDay。当然,如果您需要使用更复杂的通知模式,这不是正确的选择。
另外值得一提的是,从 iOS7 开始,由于客户要求,我必须在后台应用程序刷新中实现通知的重新安排。
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.
对此的基本解决方案是使用 RepeatInterval 来处理以特定时间间隔发生的通知。这将减少冗余通知的数量。但如果数量超过 64,那么您可以采用一种策略来使用 userInfo 字典,并在其中传递下一个通知的时间和消息,并在
- (void) application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)通知
方法被调用。这可能有点棘手,因此您必须小心,确保在 userInfo 字典中传递正确的数据并准确设置通知。
我希望这有帮助。
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.
除了先安排前 64 个通知,然后在通知启动、后台运行和启动时,检查通知数量是否少于 64 个,然后重新安排您的通知,我不知道还有什么其他方法。
我不明白为什么苹果的通知实现如此蹩脚。如果有人能找到更好的方法请告诉我。
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.
我发现这个 Swift 库正在做与我们正在寻找的几乎相同的事情。我将尝试这个并确认它是如何工作的:
https://github.com/ahmedabadie/ABNScheduler
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
Apple 文档 说:
Apple Doc says: