Accepted Reply
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.
Replies
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.
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?
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) } }
-
its 2023, when I attach the widget process to real device, it happens to me ? WILL IT WORK in normal environment ?
please check my situation at : at:https://developer.apple.com/forums/thread/650318?page=1#768972022
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?
Timeline getting called multiple times, I'm using the policy: .after(/* 1 day */)) and it's not working
im having the same issue now , the getTimeline is being called multiple times, can't figure out what's going on. plain simple entry here:
on my real calls, im calling to an api and and have a background process downloading 3 images into memory, when this happens its calling the api all those times and running the download image process all of those times, and of course it crashes at a point cuz of memory going after 30MB -- Xcode 15 --
let currentDate = Date()
let updateDate = Calendar.current.date(byAdding: .hour, value: 5, to: currentDate)!
print("NEW Current Date:\(currentDate) update Date is: \(updateDate)")
let entry = SimpleEntry(date: Date(),configuration: ConfigurationIntent(), items: DummyData.data)
let timeline = Timeline(entries: [entry], policy: .after(updateDate))
completion(timeline)
-- DEBUG console , running real device --
NEW Current Date:2023-10-18 13:58:34 +0000 update Date is: 2023-10-18 18:58:34 +0000
NEW Current Date:2023-10-18 13:58:37 +0000 update Date is: 2023-10-18 18:58:37 +0000
NEW Current Date:2023-10-18 13:58:38 +0000 update Date is: 2023-10-18 18:58:38 +0000
NEW Current Date:2023-10-18 13:58:40 +0000 update Date is: 2023-10-18 18:58:40 +0000
NEW Current Date:2023-10-18 13:58:40 +0000 update Date is: 2023-10-18 18:58:40 +0000