0

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.

Fabio M.
  • 51
  • 8
  • Maybe the delay makes the center signal changes to its store(maybe on another thread?), before `center.getPendingNotificationRequests ` is called? Just a shot in the dark though. – Fabian Aug 01 '18 at 15:18
  • But if I do a 1ms delay, it works like without a delay. – Fabio M. Aug 01 '18 at 18:33
  • Maybe a 1ms delay is not enough to reschedule since rescheduling takes 1-2ms? You could try executing `center.removePending` on the main queue and see whether it changes anything. – Fabian Aug 01 '18 at 18:37
  • Sadly it don't change anything. – Fabio M. Aug 01 '18 at 20:44

0 Answers0