If I removed a user notification and I will update my TableView with the list of pending notifications, the removed notification is still in the list. I printed the array of notifications and it is still in the array.
But if I make a minimum 3ms delay before updating, the array is right, that means without the removed notification. I don't want an delay in an final release. Thats my problem.
Here is my code to remove a notification:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
center.getPendingNotificationRequests(completionHandler: { requests in
print(requests[indexPath.row].identifier)
self.center.removePendingNotificationRequests(withIdentifiers: [requests[indexPath.row].identifier])
})
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(3) , execute: {
self.updateTable()
})
}
}
And here is my update function:
func updateTable() {
notifications = []
center.getPendingNotificationRequests(completionHandler: { requests in
for request in requests {
var info = request.content.title + "; "
let trigger: UNCalendarNotificationTrigger = request.trigger as! UNCalendarNotificationTrigger
info += request.content.subtitle + "; "
info += String(trigger.dateComponents.day!) + "."
info += String(trigger.dateComponents.month!) + "."
info += String(trigger.dateComponents.year!) + "; "
info += String(trigger.dateComponents.hour!) + ":"
info += String(trigger.dateComponents.minute!)
if self.notifications.isEmpty {
self.notifications = [info]
} else {
self.notifications.append(info)
}
}
DispatchQueue.main.async {
self.table.reloadData()
}
})
}
Thank you for your help.