gpt4 book ai didi

iOS - 安排多个本地通知,UNCalendarNotificationTrigger

转载 作者:行者123 更新时间:2023-11-28 12:26:18 26 4
gpt4 key购买 nike

我想开发一个提醒应用程序,当我们设置提醒时需要发送本地通知。我开发了一些代码,即使我设置了多个通知,也只触发一个通知。如果我在晚上 7:30、晚上 7:31、晚上 7:32 设置提醒,则通知仅在晚上 7:32 显示。

这是我的代码

    func scheduleNotification(at date: Date) {
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true)
let content = UNMutableNotificationContent()
content.title = "Reminder"
content.body = "To day is the last date for the payment of your card. Please make payment today."
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "PaymentReminderIdentifier"
let request = UNNotificationRequest(identifier: "ReminderNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
//UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}

//

func notif() {
let selectedDate = fullDate
print("Selected date: \(selectedDate)")
let delegate = UIApplication.shared.delegate as? AppDelegate
delegate?.scheduleNotification(at: selectedDate!)
}

我想在每次创建提醒时发送通知。帮我解决这个问题。谢谢...

最佳答案

每次使用不同的标识符。它会起作用

关于iOS - 安排多个本地通知,UNCalendarNotificationTrigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43291468/

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