我使用唯一標識符調度通知,因此我不必爲每個通知創建一個新的字符串。這一切都適用於調度,但問題在於試圖取消它們。調度通知的唯一標識符,Swift 3 iOS 10
這是我安排的通知代碼...
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)
這是爲了消除通知的代碼...
// 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!])
當我嘗試取消他們,他們都非常擊中,小姐。我已經通過將標識符更改爲常規字符串來測試代碼,並且所有工作都是如此,因此它絕對是唯一標識符。
有關爲每個新任務/通知創建唯一ID的任何想法/建議?
有什麼問題?什麼「他們非常受打擊和想念」甚至_mean?_請解釋什麼是問題。什麼是TaskManager,無論如何? – matt
一次只能取消一個通知(不是多個)。如果您安排通知,關閉應用程序,然後重新打開應用程序以刪除任務,則通知不會被取消。就像我說的,這一切都完美地與字符串一起工作,但使用唯一的ID是我的問題。我正在尋找另一種方式爲每個任務創建唯一的ID。 – Tai
「所有的作品完美地與一個字符串,但使用唯一的ID是我的問題」我無法弄清楚這是什麼意思。標識符_is_是一個字符串,所以我沒有得到你正在繪製的區別。你還沒有展示你的標識符是如何創建和存儲的,所以誰知道你在做什麼?到目前爲止,整個問題完全不清楚(至少對我而言)。 – matt