使用来自UNUserNotificationCenter. 我尝试删除带有一些标识符的通知:
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: identifiers)
Run Code Online (Sandbox Code Playgroud)
并从文档:
此方法异步执行,删除辅助线程上挂起的通知请求。
完成处理程序不存在。那么我怎么知道它什么时候真的被删除了呢?在继续之前,我需要确保此标识符不再存在。
我知道我可以使用下一个代码
notificationCenter.getPendingNotificationRequests { (requests) in
for request in requests {
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我在删除后立即运行此代码 - 它们仍然存在。但是一段时间后,在代码中它们消失了。当您即将达到 64 条通知的限制时,在添加新通知之前尤其重要