0

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?

kd02
  • 422
  • 5
  • 14
  • Assuming the `API.getWordOfTheDay` returns `.failure`... what happens then? It looks like *nothing* which might be the reason why your widget is not refreshing. Instead, return some error entry, so you know that the error occurred. – pawello2222 Feb 06 '21 at 11:29
  • @pawello2222 at the moment, nothing. I'll put in some error handling and check if the reload is actually working but the API request is failing hence it appearing like it's not updating. will report back. – kd02 Feb 06 '21 at 11:56

0 Answers0