我的应用程序WillEnterForeground函数在iOS 13中不起作用.我能做什么?



我想在应用进入前台时从通知中心删除所有本地通知。我在应用程序委托中使用了applicationWillEnterForeground函数:

func applicationWillEnterForeground(_ application: UIApplication) {
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications() // To remove all delivered notifications
center.removeAllPendingNotificationRequests()
}

不幸的是,该函数无法运行。我在某处读到,其原因可能是iOS中的多任务处理。我的问题是如何关闭多任务处理?或者,如果有人对函数不运行有其他想法。

如果您的applicationWillEnterForeground不起作用,您可以在sceneDelegate中使用sceneWillEnterForeground(_ scene: UIScene)方法。

最新更新