Widget Timelines With Clock-Based App

My app, Class Clock, currently offers a Today Widget that displays a circular timer similar to the timer in iOS 13 and a few labels to show the user how much time is left in class. With the new WidgetKit, I understand the widget's timeline is only updated every so often. However, if the circular timer needs to load every minute, how can this be achieved? Could I perhaps tell the timeline that Class A is from 10 - 11 and the widget then animates between 10 and 11 on its own without calling a new timeline every minute? Ideally, the circular progress indicator would continue to animate its SwiftUI Circle trim percentage every second or minute.
Answered by Systems Engineer in 614388022
You are correct that the WidgetKit Extension is not alive whenever the widget is visible; instead, you provide entries into the future. However, you can display relative dates which are updated live while the widget is on screen. Checkout "Keeping a Widget Up To Date" to see how to use the relative date provider.

Set the date to the time that class ends as voila, it will update every second on the homescreen! However, you cannot update views to the time other than the relative date text label. So you cannot replicate the Clock widget for example and have second hands on a clock tick by while the widget is visible. Sorry.

Awesome app idea though, good luck!
I would like to add that I am aware of the SwiftUI Timer Text which would allow the widget to continue displaying time information continuously. However, this would still not solve the ability for the circle timer to animate continuously or even on a minute basis.
Accepted Answer
You are correct that the WidgetKit Extension is not alive whenever the widget is visible; instead, you provide entries into the future. However, you can display relative dates which are updated live while the widget is on screen. Checkout "Keeping a Widget Up To Date" to see how to use the relative date provider.

Set the date to the time that class ends as voila, it will update every second on the homescreen! However, you cannot update views to the time other than the relative date text label. So you cannot replicate the Clock widget for example and have second hands on a clock tick by while the widget is visible. Sorry.

Awesome app idea though, good luck!
I've been following this thread and reading through the docs and I'm pretty stuck on something. I'm able to show the difference between 2 times. I'm able to set a countdown timer. But I'm having issues with 2 things.
  1. How would I show the current time on a widget (and keep it up to date)

  2. Do a count up timer

Thanks!
With the current APIs you couldn't show the current time, unfortunately.

I'm not completely sure what you mean by a "count up timer", but if you use the Text APIs with a .offset style and specify a date that's in the past, that will count up from that date.

For any formatting that you want to do but cannot with the current APIs, please file Feedback Assistant requests, with details of what you're looking to do.
Ah bummer... So I've tried out the .offset style, but it automatically formats it as "+5 minutes" or "-30 seconds". Is there any way to remove the access information to just show the number?
In beta 1 it seemed like widgets refreshed from the timeline every few seconds. Since beta 2 it seems to be much less frequent, like maybe once an hour. I am fine with not updating every second, but once a minute seems quite reasonable given the low cost of the widget views.

I think this will be a problem for apps which want to show timely glanceable information (for example the system clocks widget does not update every minute). I will raise a feedback.
That’s awesome! Thank you for the support. The current API’s already allow for countdown timers by second, so this doesn’t seem too, too unreasonable to me.
Any new information here? I am seeing lots of widget apps display current time. Wondering what I am missing here.
It seems that the DClock app can somehow update the analog clock every second. Their watch has a second hand that updates every second. Any ideas how we can do the same?
For the DClock in the AppStore, I suspect that the app has used private API (same as the clock.app by Apple) to animate the second hand smoothly. I am not here to disclose the API but a simple Google search will reveal.

It is quite obvious that it is true, since the animation is absolute in sync with Apple's own clock. Frequent calls to WidgetCenter.shared.reloadAllTimelines() can never achieve this.

Just two requests to Apple's Widget team:
1) May Apple please take action and remove any app if private API is used. It is unfair that some developers are gaining advantage.
2) May Apple please release this API as public. A clock widget with hands animation makes sense.



Widgetsmith is able to show a fuzzy clock (“twenty past four”) with very accurate time. I thought it was possible to have an update every few minutes. I wanted to implement one in a non-English but could not get that kind of update. I wonder what they are doing there.

As a late reply to @levikline, I've been working on a similar app. Apple does state on their "Keeping a Widget Up to Date" documents that formatting a date as a Text.DateStyle is the only way to keep a widget up to date without timeline entries, but I've been playing with using ProgressView(timerInterval:countsDown:) with promising results. I'm having trouble using dates programmed in the entry, but if you use some code like the following, it seems to continuously update within one Timeline Entry

ProgressView(timerInterval: Calendar.current.date(bySettingHour: 13, minute: 00, second: 00, of: .now)!...Calendar.current.date(bySettingHour: 14, minute: 07, second: 00, of: .now)!, countsDown: false)
Widget Timelines With Clock-Based App
 
 
Q