开发一个穆斯林祷告时间的软件,每天需要有五次通知。所以要实现每天在特定的时间发送通知。
我给每次祷告都创建了对应通知,分配了不同的时间。
但是问题是每次运行或重启应用在通知中心都会有一条通知。我不要这条多余的通知。谢谢。
在调度通知之前,您可以使用 UNUserNotificationCenter.current().removeAllPendingNotificationRequests() 方法删除所有挂起的通知请求。这样,在调度新通知之前,您就可以删除所有旧通知。
例如:
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
// Schedule new notifications here
这样,当应用启动时,就不会在通知中心中显示多余的通知。