Hi all,
I've got a pretty simple app (basically a Hootsuite like and light).
I'd was hoping to create a widget that show the last post if it is today, or an view that encourages the user to create a new post.
To that purpose, I create a Codable model that I store in the shared UserDefaults (suiteName) and when I do so, I call the fefrshtimeline as follows :
The thing is, I put a print in the timeLine and it's never called. I also tried to change the snapShot method, nothing works so far.
Here are both methods from the Widget :
The widget is static configuration widget.
I do enter in WidgetCenter.shared.reloadTimelines, but never in the protocol methods.
Thanks for your help :-)
I've got a pretty simple app (basically a Hootsuite like and light).
I'd was hoping to create a widget that show the last post if it is today, or an view that encourages the user to create a new post.
To that purpose, I create a Codable model that I store in the shared UserDefaults (suiteName) and when I do so, I call the fefrshtimeline as follows :
Code Block func save() { let encoder = JSONEncoder() if let data = try? encoder.encode(self) { UserDefaults.group.set(data, forKey: "lastPost") WidgetCenter.shared.getCurrentConfigurations { (result) in guard case .success(let widgets) = result else { return } widgets.forEach { widget in WidgetCenter.shared.reloadTimelines(ofKind: widget.kind) } } } }
The thing is, I put a print in the timeLine and it's never called. I also tried to change the snapShot method, nothing works so far.
Here are both methods from the Widget :
Code Block func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { print("🏵 getSnapshot") if let model = ExtensionSharedModel.retrieve(), model.date.isToday { print("🏵 add model \(model.displayName)") completion(SimpleEntry(date: Date(), model: model)) } else { print("🏵 no models to add...") completion(SimpleEntry(date: Date())) } } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { print("🏵 getTimeline") var entries: [SimpleEntry] = [] if let model = ExtensionSharedModel.retrieve(), model.date.isToday { print("🏵 add model \(model.displayName)") entries = [SimpleEntry(date: Date(), model: model)] } else { print("🏵 no models to add...") entries = [SimpleEntry(date: Date())] } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) }
The widget is static configuration widget.
I do enter in WidgetCenter.shared.reloadTimelines, but never in the protocol methods.
Thanks for your help :-)