WidgetKit: reload by location?

Hi,
I was wondering if it's possible to reload the widget data by location. For e.g. if your location changed significantly, how would we force the widget to reload it's data?
Thanks.
Answered by Documentation Engineer in 614694022
@Rubenfern is correct, your app can monitor location changes and use the WidgetCenter APIs to reload affected widgets. A couple things I'd suggest you keep in mind:
  • Only reload the widgets that are affected. You can get some details in the Keeping a Widget Up To Date article

  • Consider the granularity that would make sense for the widget to be updated, especially since widget reloads are not guaranteed to happen immediately

If the results you get don't meet your needs, please file Feedback Assistant reports with details of what you're trying to do and the results you get. This is a new API so getting your feedback about what works and what doesn't is very important to us!
Accepted Answer
Maybe your iOS app can check if the user location changes and then you can reload the timeline of your widget using WidgetCenter.shared.reloadAllTimelines().

@Rubenfern is correct, your app can monitor location changes and use the WidgetCenter APIs to reload affected widgets. A couple things I'd suggest you keep in mind:
  • Only reload the widgets that are affected. You can get some details in the Keeping a Widget Up To Date article

  • Consider the granularity that would make sense for the widget to be updated, especially since widget reloads are not guaranteed to happen immediately

If the results you get don't meet your needs, please file Feedback Assistant reports with details of what you're trying to do and the results you get. This is a new API so getting your feedback about what works and what doesn't is very important to us!
WidgetKit: reload by location?
 
 
Q