I have a widget that is meant to update daily at midnight, my code for the timeline looks like this:
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<ViewModel>) -> Void) {
// Generate a timeline with one entry that refreshes at midnight.
let currentDate = Date()
let endOfDay = calendar.date(byAdding: .day, value: 1, to: currentDate)!
API.getWordOfTheDay(for: currentDate) { result in
switch result {
case .success(let wordOfTheDay):
let entry = ViewModel(date: currentDate, wordOfTheDay: wordOfTheDay, configuration: configuration)
let timeline = Timeline(entries: [entry], policy: .after(endOfDay))
completion(timeline)
case .failure:
break
}
}
}
The problem is the widget never seems to update the next day when I check it. I've tried changing the reload policy to .atEnd
but that also doesn't work.
Any suggestions what it might be or what I'm doing wrong?