gpt4 book ai didi

ios - 取消本地通知

转载 作者:搜寻专家 更新时间:2023-10-31 22:29:53 32 4
gpt4 key购买 nike

我想列出预定的本地通知以检查触发日期,取消好的通知。

这就是我添加本地通知的方式:

let notification = UILocalNotification()
notification.fireDate = date
notification.alertBody = message
notification.soundName = UILocalNotificationDefaultSoundName
notification.timeZone = NSTimeZone.defaultTimeZone()

这就是我列出所有通知以找到好的通知的方式:

for oneEvent in UIApplication.sharedApplication().scheduledLocalNotifications! {
if date == notification.fireDate {
app.cancelLocalNotification(notification)
}
}

问题是我创建了很多通知,而 scheduledLocalNotifications 中总是只有一个通知!

通知已正确触发,但我无法检索它们是 scheduledLocalNotifications 变量。

最佳答案

我没有收到你的问题,但我对下面的代码有一些疑问试试这个:

你必须在创建通知后写这一行。

UIApplication.sharedApplication().scheduleLocalNotification(notification)

然后

for oneEvent in UIApplication.sharedApplication().scheduledLocalNotifications! {
if date == oneEvent.fireDate {
app.cancelLocalNotification(oneEvent)
}
}

关于ios - 取消本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40673719/

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