Ios 删除swift 3中的通知
您好,我正在开发一个应用程序,该应用程序为我提供特定时间和日期的通知,并显示在TableViewController中。因此,表中有多个通知。如何删除特定通知? 如果我删除了包含通知的行,它仍然不会被删除Ios 删除swift 3中的通知,ios,swift,Ios,Swift,您好,我正在开发一个应用程序,该应用程序为我提供特定时间和日期的通知,并显示在TableViewController中。因此,表中有多个通知。如何删除特定通知? 如果我删除了包含通知的行,它仍然不会被删除 override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { let co
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let context = getContext()
if editingStyle == .delete {
// Delete the row from the data source
context.delete(names[(indexPath as NSIndexPath).row])
let a = (names[(indexPath as NSIndexPath).row])
let center = UNUserNotificationCenter.current()
let notifToDelete = a.name
center.getPendingNotificationRequests { (notifications) in
print(notifications)
for item in notifications {
if(item.identifier.contains(notifToDelete!))
{
center.removePendingNotificationRequests(withIdentifiers: [item.identifier])
}
}
}
do {
try context.save ()
}catch {
let saveError = error as NSError
print(saveError)
}
names.remove(at: (indexPath as NSIndexPath).row)
tableView.deleteRows(at: [indexPath], with: .automatic)
这不会以任何方式影响。通知仍在设置的时间运行。(通知在不同的视图控制器中设置) 删除这段不必要的代码:
center.getPendingNotificationRequests { (notifications) in
print(notifications)
for item in notifications {
if(item.identifier.contains(notifToDelete!))
{
center.removePendingNotificationRequests(withIdentifiers: [item.identifier])
}
}
}
相反,请执行以下操作:
center.removePendingNotificationRequests(withIdentifiers: [notifToDelete])
非常感谢。删除了通知,但删除了上次保存的通知。哦!!我发现我为通知设置的标识符与我给它的要删除的标识符不同。非常感谢!!别担心。如果我的回答有用的话,你能接受吗!成功了!别担心。干杯