让swiftUI在后台运行计时器

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

我希望计时器在后台继续运行。

这是计时器的当前代码:

struct ContentView: View {
@State var timeRemaining = 10
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

var body: some View {
    Text("\(timeRemaining)")
        .onReceive(timer) { _ in
            if self.timeRemaining > 0 {
                self.timeRemaining -= 1
            }
        }
} }

我如何使其在后台继续运行?

swift timer swiftui countdowntimer
1个回答
0
投票
关于后台任务有几种解释方式……例如:https://www.raywenderlich.com/5817-background-modes-tutorial-getting-started
© www.soinside.com 2019 - 2024. All rights reserved.