I'm building an iOS widget that performs a network call and displays some data to the user. The data changes over time so I want the widget to update once every hour or so. This is my code for the timeline provider:
func getTimeline(for configuration: SelectChannelIntent, in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> Void) {
Task {
let result = try await fetchData(for: configuration.channel)
let timeline = Timeline(
entries: [result],
policy: .after(Calendar.current.date(byAdding: .minute, value: 60, to: Date())!)
)
completion(timeline)
}
}
Testing this on a physical device resulted in the widget being updated at completely random times. Usually it updated between every 15-45 minutes. I don't want it to update that frequently since the data doesn't change that often. I would also like to allow the user to modify the update frequency in the future.
I've even tried increasing the policy to update after 24 hours, but it still updates every 15-45 minutes. How can I tell the widget when to update?