我正在使用唯一标识符安排通知,因此我不必为每个通知创建一个新字符串。这一切都适用于调度,但问题在于试图取消它们。
这是我安排通知的代码...
let notifIdentifier = TaskManager.notification2.userInfo.description as String!
let trigger = UNCalendarNotificationTrigger(dateMatching: components , repeats: true)
let request = UNNotificationRequest(identifier: notifIdentifier! , content: TaskManager.notification2, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
这是取消通知的代码...
// Deletion of Cells ...
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let managedObject: NSManagedObject = frc.object(at: indexPath) as! NSManagedObject
context.delete(managedObject)
if tableView == TaskTableViews {
let itemController = TaskManager()
let nItem: List = frc.object(at: indexPath) as! List
itemController.nItem = nItem
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [itemController.notifIdentifier!] )
当我试图取消它们时,它们非常受欢迎。我已经通过将标识符更改为常规字符串来测试代码,并且一切正常,因此它绝对是唯一标识符。
关于为每个新任务/通知创建唯一 ID 的任何想法/建议?