I want help in giving a refreshing policy that refreshes once a day.
Solved Answer
Hi,
To do this, you may pass a TimelineReloadPolicy which explicitly asks to be updated tomorrow. Such as
A similar example is described in TimelineProvider's documentation.
To do this, you may pass a TimelineReloadPolicy which explicitly asks to be updated tomorrow. Such as
Code Block swift /* Return timelines and set policy to reload tomorrow */ func timeline(with context: Context, completion: @escaping (Timeline<MyEntryType>) -> ()) { ... let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())! let timeline = Timeline<MyEntryType>(entries: entries, policy: .after(tomorrow)) ... }
A similar example is described in TimelineProvider's documentation.
7 Replies
Hi,
To do this, you may pass a TimelineReloadPolicy which explicitly asks to be updated tomorrow. Such as
A similar example is described in TimelineProvider's documentation.
To do this, you may pass a TimelineReloadPolicy which explicitly asks to be updated tomorrow. Such as
Code Block swift /* Return timelines and set policy to reload tomorrow */ func timeline(with context: Context, completion: @escaping (Timeline<MyEntryType>) -> ()) { ... let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())! let timeline = Timeline<MyEntryType>(entries: entries, policy: .after(tomorrow)) ... }
A similar example is described in TimelineProvider's documentation.
Thanks A Lot 😃
I’ve seen an strange behavior with te refresh policy.
if you put a print(“hello”) in the timeline function, it will print a bunch of hello per second, and the CPU will be over 50%.
I would expect it to print hello tomorrow, but it’s no happening.
maybe it’s a bug?
Does it happens to you?
if you put a print(“hello”) in the timeline function, it will print a bunch of hello per second, and the CPU will be over 50%.
I would expect it to print hello tomorrow, but it’s no happening.
maybe it’s a bug?
Does it happens to you?
@JugaNet happens for me as well which is a really big problem as I'm calling an API :/ The Timeline seems to ignore the policy, perhaps i'm missing something? Here's my code at least, is this happening for anyone else?
Code Block swift func timeline(with context: Context, completion: @escaping (Timeline<ChannelEntry>) -> ()) { let currentDate = Date() let refreshDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)! guard let channels = try? JSONDecoder().decode([Channel].self, from: channelsData) else { return } update_channel(channel, token) { updatedChannel in let entry = ChannelEntry(date: currentDate, channel: channels[0]) let timeline = Timeline(entries: [entry], policy: .after(refreshDate)) completion(timeline) } }
Sorry you ran into this. This is a known issue where if you have the debugger attached to the widget process, the timeline is excessively reloaded. Please keep an eye on future betas where this will get fixed.
Post marked as unsolved
Up vote reply of Developer Tools Engineer
Down vote reply of Developer Tools Engineer
I use Xcode 12.0 beta 4 and still have the same problem.Sorry you ran into this. This is a known issue where if you have the debugger attached to the widget process, the timeline is excessively reloaded. Please keep an eye on future betas where this will get fixed.
Any news?
so we at 14.3 and it's still buggy, how are we suppose to develop like this?
Timeline getting called multiple times, I'm using the policy: .after(/* 1 day */)) and it's not working
Timeline getting called multiple times, I'm using the policy: .after(/* 1 day */)) and it's not working