Reputation: 10887
I have a simple widget that reads a timer on my app, a start and end Date
. The view then displays these dates on a watch complication using WidgetKit. The data for them is stored in UserDefaults and then the timeline adds two entries when it gets triggered to update from the app using WidgetCenter.shared.reloadAllTimelines()
func getTimeline(in context: Context, completion: u/escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
if let timerStart = UserDefaults.object(key: "widgetStart") as? Date,
let timerEnd = UserDefaults.object(key: "widgetEnd") as? Date {
entries.append(SimpleEntry(date: timerStart, timerEnd: timerEnd))
entries.append(SimpleEntry(date: timerEnd, timerEnd: timerStart))
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
My question has to do with how the timeline is updated, reading around it says that a timeline cannot be for more than 24 hours. My UserDefaults will last more than that so does the timeline basically re-run getTimeline()
every 24 hours or is there a different way it's handled? Does the policy: .atEnd
have any effect on when it's refreshed if longer than the 24 hours?
For example, if my timer ends in a week, will the timeline just re-run getTimeline
daily?
Upvotes: 0
Views: 33