因为现在不推荐UILocalNotification,所以我将代码移到了新的UNNotificationRequest API中。
它声明:'cancelLocalNotification‘在iOS 10.0中被废弃:使用UserNotifications框架的-[UNUserNotificationCenter removePendingNotificationRequestsWithIdentifiers:]
但这似乎是不平等的--尽管我可以随时使用cancelLocalNotification删除消息(即使它们是显示/传递的),但似乎removePendingNotificationRequestsWithIdentifiers只删除未传递的通知。真烦人。
因此,我的问题是:是否有一种有效的方法来删除与UNNotificationRequest一起排队的通知,还是应该忽略那些弃用警告?
发布于 2017-08-11 12:50:44
还可以使用removeDeliveredNotifications(withIdentifiers:)函数从通知中心删除已经传递的通知。有关更多信息,请参见文档
发布于 2018-04-19 05:14:57
Swift 4和Swift 5
如果要删除所有 UNNotificationRequest项,可以使用:
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()https://stackoverflow.com/questions/45635400
复制相似问题