How can widget be updated every half a second?

Many widgets running on iOS 16 is able to update their UI as frequent as half a second or one second.

How is this done?

You have a limited with timeline refreshes (every 15-30 minutes at most) https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date

A widget’s budget applies to a 24-hour period. WidgetKit tunes the 24-hour window to the user’s daily usage pattern, which means the daily budget doesn’t necessarily reset at exactly midnight. For a widget the user frequently views, a daily budget typically includes from 40 to 70 refreshes. This rate roughly translates to widget reloads every 15 to 60 minutes, but it’s common for these intervals to vary due to the many factors involved.

You also cannot supply a long list of entries (in my test, something beyond 400 Entries in the timeline causes the widget to not update)

Also, the View itself cannot be update every second either even your Entries are 1 second apart. The UI seems to be update every 2 second at the fastest and ignore in between entries.

  • @dyyi Did you find out how we can refresh every second? I want to show a digital clock in widget.

Add a Comment

Replies

The UI is actually not updating based on individual states being consumed through timeline refreshes, but instead set to an "end state" through which the middle-states are being interoperated.

For example, to display a countdown you can use Text(_:style) with a relative style which would result in a the view remaining up-to-date outside of timeline momentum. In this way, the only cases you need to refresh the timeline would be to add, remove, or replace the widget's countdown end date.