我想在应用进入前台时从通知中心删除所有本地通知。我在App Delegate中使用了
applicationWillEnterForeground
函数:
func applicationWillEnterForeground(_ application: UIApplication) {
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications() // To remove all delivered notifications
center.removeAllPendingNotificationRequests()
}
不幸的是,该功能没有运行。我在某处读到,其原因可能是 iOS 中的多任务处理。我的问题是如何关闭多任务处理?或者,如果有人有其他想法为什么该功能无法运行。
如果你的
sceneWillEnterForeground(_ scene: UIScene)
不工作,你可以使用
sceneDelegate
中的
applicationWillEnterForeground
方法