gpt4 book ai didi

ios - 安排无限数量的本地通知

转载 作者:行者123 更新时间:2023-12-01 16:01:16 25 4
gpt4 key购买 nike

我有一个允许用户创建重复事件的应用程序。每个事件在一天中的特定时间可能有也可能没有提醒/警报。如果有,应用程序会发送 本地通知 在一天中的那个时候。

事件存储在 核心数据 .

Event(name: "Go to London", 
date: 2020-04-03 21:40:55.419925+0200,
reminders: [2020-04-03 20:00:00.419925+0200,
2020-04-03 10:00:00.419925+0200,
2020-04-03 12:00:00.419925+0200]
)

事件可能发生在一年中的每一天或接下来 X 年的每一天。

用户每天可以创建无限数量的事件。因此,要发送的通知总数很容易超过 64(您可以在 iOS 中安排的本地通知总数)。因此,当应用程序处于前台时,我无法安排所有通知。

如果待处理的通知少于 64 个,我需要一种机制来定期安排通知。即使应用程序在后台,也应该这样做。

如果您提供解决方案或指导我为这种情况找到解决方案,我会很高兴。

信息

我尝试设置 定时器 定期检查待处理通知的总数及其截止日期。 .但它不起作用,因为一旦应用程序进入后台,计时器就不会触发。

最佳答案

我不确定我是否正确理解您的问题。但我的印象如下:

您的用户设置和更新事件数据库,其中每个事件都有特定的日期和时间。
他们这样做只是将新事件输入数据库。
然后很容易获取第一个 n (比如 10 个)来自数据库的事件。
需要获取多个,因为不能保证本地通知的传递,请参阅 the docs :

Every attempt is made to deliver local and remote notifications in a timely manner, but delivery isn't guaranteed.



注册这些 n通知中心的本地通知,并取消任何不再属于 n 的事件的通知下一个。 The docs说:

Typically, you cancel a request when conditions change and you no longer need to notify the user. For example, if the user completes a reminder, you would cancel any active requests associated with that reminder. To cancel an active notification request, call the removePendingNotificationRequests(withIdentifiers:) or removePendingNotificationRequests(withIdentifiers:) method of UNUserNotificationCenter.



因此,即使您的应用程序处于后台或挂起状态,本地通知也会将其唤醒,处理事件,将其从数据库中删除,并更新 n接下来的事件。即使无法传递通知(这不太可能,但可能),您也可以处理错过的事件,并安排下一个事件。
我希望这能满足你的要求!

关于ios - 安排无限数量的本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61031931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com