Xcode - Frequently update Widget Extension

Viewed 332

I am creating a widget for my app that get's info from API, such as car battery percentage, range remaining and so on.. I understand that after iOS 14 Today Extension has been deprecated where you could run code every time the widget appear on the screen. How can I do something like this when using Widget Extension? What would be the best approach here?

EDIT: (Since @El Tomato complains about my phrasing)

How would you guys suggest I do this, in this case?

1 Answers

There is apple's article about updating Widget Extension https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date

For predictable events all is simple: you are filling timeline as much as you can predict them

For unpredictable events it's quite complicated challenge. Somebody need to refresh your's widget with WidgetCenter.shared.reload... calls. In your's case it looks like it can be done from navigation application running in the background. Also notification extensions can reload widgets, that's mean that you can reload widget from push notifications

Doesn't rely on periodic refreshing: Apple doesn't recommend to use interval less then 15 minutes and even if you decide to use it iOS can decide to not refresh widget even for several hours.

Background pushes and background fetches also can be used for widget refreshing, but system limit them in the same unreliable way like with refresh intervals. So they can be used only for the last hope approach.

Related