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

标签 ios swift notifications uilocalnotification localnotification

我想开发一个提醒应用程序,当我们设置提醒时需要发送本地通知。我开发了一些代码,即使我设置了多个通知,也只触发一个通知。如果我在晚上 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/

相关文章:

json - 需要一些帮助在 POST 请求后使用 JSON 数据填充 tableview

ios - 使用 UIDatePicker 在特定时间停止通知

android - 获取有关点击通知的应用程序运行信息

ios - 使用 ASIS3 启用 HTTPS

ios - 仅当满足某些条件时才调用 Safari 内容拦截器扩展?

objective-c - 重复使用细胞... :(

Android:AlarmManager 一直显示相同的通知

objective-c - 在 Core Data 中保存 MKOverlay 对象

swift - 我如何遵守与 Actor 的协议(protocol)?

swift - 快速使用数组从 FMDB 中删除数据