I am scheduling notifications with Unique Identifiers so I don't have to make a new String for each notification. This all works well for scheduling but the problem lies in trying to cancel them.
This is my code for scheduling notifications...
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)
This is the code for cancelling notifications ...
// 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!] )
When I try to cancel them, they are very hit and miss. I have tested the code by changing the identifier to a regular String and everything works as it should so its definitely the unique identifier.
Any thoughts/ suggestions on creating a unique ID for every new task/notification?