0

In the following example, I create 4 timeline entries in one-second intervals, specifying the timeline reload policy .atEnd.

func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
    let currentDate = Date()
    var entries: [SimpleEntry] = []

    for secondOffset in 0...3 {
        let entryDate = Calendar.current.date(byAdding: .second, value: secondOffset, to: currentDate)!
        let entry = SimpleEntry(date: entryDate, configuration: configuration)

        entries.append(entry)
    }

    completion(Timeline(entries: entries, policy: .atEnd))
}

The widget view will show the second of the timeline entry's date, just to make it visible to the user that the widget has been updated.

struct MyWidgetEntryView : View {
    var entry: Provider.Entry
    
    var body: some View {
        VStack {
            Text("\(Calendar.current.component(.second, from: entry.date))")
        }
    }
}

Whenever I run this on the simulator or an actual iPhone, the widget will count up 4 times, e.g. showing "17", "18", "19", "20". After that, it'll stop updating.

I expected WidgetKit to request a new timeline at this point, since the timeline reload policy .atEnd has been specified.

I'm aware that in this case the date of the last entry only signifies the earliest date for a new timeline to be requested, but it seems that a new timeline will never be requested, even after minutes of waiting or locking/unlocking the phone etc.

I have found this possibly related question, but my example seems to be even simpler, so I think it might be worth asking.

Am I misunderstanding how the timeline policy works?

waldrumpus
  • 2,540
  • 18
  • 44
  • You can't create an entry every 1 second - the interval is too short. Try longer intervals like 5 minutes. – pawello2222 Mar 06 '21 at 11:00
  • @pawello2222 I was afraid that might become a problem - so there's no way to implement a timer widget that's precise down to the second? – waldrumpus Mar 06 '21 at 11:28
  • 1
    No, at least officially - this might help you: https://stackoverflow.com/a/66408154/8697793 – pawello2222 Mar 06 '21 at 23:17

0 Answers0