Xcode、Swift 中的多个通知 3

Multiple notifications in Xcode, Swift 3

首先我想说我一直在寻找我的问题的答案,但到目前为止我找到的唯一东西是旧版本 Swift 的答案或答案没有具体回答我的问题。

背景资料:
我正在尝试开发一个可以在设定的时间间隔内提醒您的应用程序。现在这有效,因为您只设置了 1 个提醒。但是,如果我将间隔设置为 20 秒,启动应用程序,设置 2 个通知并关闭应用程序,只有第二个通知会在 20 秒后显示。第一个通知被第二个通知覆盖。

问题:我如何确保用户请求的所有通知都实际发送并且没有通知覆盖前一个通知?

通知代码:

    let tijd = 20 //20 is just for the test, normally there is more code to it

    // Notification
    let content = UNMutableNotificationContent()
    content.title = "Notification title"//title
    content.body = "Notification body" //body
    content.badge = 1
    content.sound = UNNotificationSound.default()

    // Timer
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(tijd), repeats: false)
    let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

此代码存储在 UITableView 单元格中。

好的,我明白了!

这个答案导致了我遇到的同样问题。我必须为每个通知设置不同的标识符!所以我现在的代码是:

let request = UNNotificationRequest(identifier: bezigheid, content: content, trigger: trigger)

bezigheid 在每个单元格中都是不同的。对其进行了测试,现在我收到了 2 条不同的通知!