删除用户通知后迅速执行,我需要熟食店来更新待处理的通知

时间:2018-08-01 13:20:52

标签: ios swift unusernotificationcenter

如果删除了用户通知,并且将使用挂起的通知列表更新TableView,则删除的通知仍在列表中。我打印了通知数组,但仍在数组中。

但是如果我在更新之前至少延迟3毫秒,则该数组是正确的,这意味着没有删除的通知。我不想延迟最终版本。那是我的问题。

这是我删除通知的代码:

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()
        })
    }
}

这是我的更新功能:

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()
        }
    })
}

谢谢您的帮助。

0 个答案:

没有答案