取消 UNNotificationRequest

coy*_*yer 5 ios swift unnotificationrequest

因为UILocalNotification现在已弃用,所以我将代码移至新UNNotificationRequestAPI。

它指出:' cancelLocalNotification ' 在 iOS 10.0 中被弃用:使用 UserNotifications Framework's-[UNUserNotificationCenter removePendingNotificationRequestsWithIdentifiers:]

但它似乎并不相等-虽然我可以随时删除消息cancelLocalNotification(即使它们已显示/已发送),但似乎removePendingNotificationRequestsWithIdentifiers只能删除未发送的通知。这真的很烦人。

所以我的问题是:是否有一种有效的方法可以删除排队的通知,UNNotificationRequest或者我应该忽略那些弃用警告?

Dáv*_*tor 6

您还可以使用该removeDeliveredNotifications(withIdentifiers:)功能从通知中心删除已发送的通知。有关更多信息,请参阅文档