How to Achieve Precise Updates with getTimeline in iOS Widget Development

71 views Asked by At

I'm working on developing a toolset for iOS, and I'm encountering an issue with the getTimeline method. I've set refresh times for the timeline, intending it to reload at specific hours and minutes daily.

However, during my tests, the timeline reload doesn't happen exactly at the specified time; there's a delay of up to 2-3 minutes before the update kicks in. How can I ensure a more precise update at the exact minute I've set for the reload to avoid this delay?

Code Example:

func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> ()) {
    let currentDate = Date()

    // Example target dates 
    let targetDate1 = Calendar.current.date(bySettingHour: 10, minute: 30, second: 0, of: currentDate)!
    let targetDate2 = Calendar.current.date(bySettingHour: 15, minute: 0, second: 0, of: currentDate)!

   

    // Generate timeline entries
    let entries = [
        SimpleEntry(date: currentDate, yourData: "Timeline Entry 1"),
        SimpleEntry(date: targetDate1, yourData: "Timeline Entry 2"),
        SimpleEntry(date: targetDate2, yourData: "Timeline Entry 3")
       
    ]

    // Provide the timeline to the widget
    let timeline = Timeline(entries: entries, policy: .atEnd)
    completion(timeline)
}
0

There are 0 answers