我的 applicationWillEnterForeground 函数在 iOS 13 中不起作用。我该怎么办?

问题描述 投票:0回答:1

我想在应用进入前台时从通知中心删除所有本地通知。我在App Delegate中使用了

applicationWillEnterForeground
函数:

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

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

ios swift appdelegate multitasking unusernotificationcenter
1个回答
0
投票

如果你的

sceneWillEnterForeground(_ scene: UIScene)
不工作
,你可以使用
sceneDelegate
中的
applicationWillEnterForeground

方法
© www.soinside.com 2019 - 2024. All rights reserved.