gpt4 book ai didi

ios - 如何在应用程序重新打开时重置本地通知

转载 作者:行者123 更新时间:2023-11-29 01:05:56 25 4
gpt4 key购买 nike

我正在开发一个具有本地通知自定义重复间隔的提醒应用程序。我基本上想要的是触发 DueDate 通知,然后触发后续通知。

所以 Notification1.fireDate = DueDate.date

Notification2.fireDate = DueDate.date.dateByAdding(1000)

& 继续 10 次左右。然后当应用程序再次激活时,我希望通知行再次循环但在最后一个通知之后开始,就像队列一样。

这一切都是为了创造自定义重复间隔的错觉。这是我的灵感来源,因此可以做到 https://stackoverflow.com/a/5765870/5601784

最佳答案

如果您不更改fireDate,那么删除之前设置的通知并重新设置是没有意义的。但是,要删除您的应用设置的所有通知,您可以执行此操作。

UIApplication.shared.cancelAllLocalNotifications()

let app: UIApplication = UIApplication.shared
for event in app.scheduledLocalNotifications! {
let notification = event as UILocalNotification
app.cancelLocalNotification(notification)
}
print(app.scheduledLocalNotifications!.count))//prints -- 0

然后您可以使用新信息设置 UILocalNotification。

关于ios - 如何在应用程序重新打开时重置本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36363792/

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