SwiftUI: Timer.publish not working on Lock Screen widget iOS 16

299 Views Asked by At

I am implementing timer on lock screen widget using Timer.publish and .onReceive on Text. But the timer is not firing. let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

I have a Text() in ZStack which I want to update.

1

There are 1 best solutions below

0
malhal On

Widgets are static, your app sends an encoding of the View structs to the lock screen so none of the actions work. However, there are ways to request a refresh, see Keeping a Widget Up To Date | Apple Developer Documentation