我目前有这个:
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
...
}
并且当我不退出该应用程序时它就起作用了,它只是在后台运行,但是当我退出它时,其中的应该检查一段时间的代码不起作用。
我也尝试将其放入
.onAppear() {
但这也不起作用:/
在应用程序关闭后又打开后,如何立即执行操作?
答案 0 :(得分:0)
您可以尝试添加以下代码以在应用启动时执行操作:
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
// do your action here
....
}