StaticConfiguration.init(kind:provider:placeholder:content:) deprecated warning

Apple Recommended

Replies

TimelineProvider now has placeholder(with: Context).
Is there a reason why the new placeholder function does not have access to the Intent data? It would be useful to be able to access some settings from the IntentConfiguration to e.g. use colors the user selected also for the placeholder view. Or did I miss something?

Markus
ok, I implemented the new (in beta 3) method: placeholder(with: Context). The widget shows up on the device when I run locally, but when distributed using TestFlight, HomeWidget disappears and cannot be added.

Here his my code for the TimeLineProvider. What am I missing?

Code Block struct Provider: TimelineProvider {
    public typealias Entry = SimpleEntry
    let dict_dummy = ["Gizmo": ["SOC": 89, "ratedRange": 196, "estimatedRange": 185, "unit": "mi", "isTestUser": true]]
    public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
        var  dict = defaults?.dictionary(forKey: Constants.WIDGET_DICT)
        if dict == nil {
            dict = dict_dummy
        }
        let entry = SimpleEntry(date: Date(), dict: dict)
        completion(entry)
    }
    public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        let currentDate = Date()
        let refreshDate = Calendar.current.date(byAdding: .minute, value: 10, to: currentDate)!
        let dict = defaults?.dictionary(forKey: Constants.WIDGET_DICT)
        let entry = SimpleEntry(date: Date(), dict: dict)
        let timeline = Timeline(entries: [entry], policy: .after(refreshDate))
        completion(timeline)
    }
    func placeholder(with: Context) -> SimpleEntry {
        let entry = SimpleEntry(date: Date(), dict: dict_dummy)
        return entry
    }
}
@main
struct HomeWidget: Widget {
    private let kind: String = "HomeWidget"
    public var body: some WidgetConfiguration {
        StaticConfiguration(kind: kind, provider: Provider()) { entry in
            HomeWidgetEntryView(entry: entry)
        }
        .configurationDisplayName("Stats Widget")
        .description("Shows battery SoC and Rated Range")
        .supportedFamilies([.systemSmall, .systemMedium])
    }
}


Is there any documentation available to indicate the difference between snapshot and placeholder. While I do see that @pdm noted that snapshot is asynchronous, I was under the impression that snapshot's goal is to provide a quick representation of the widget, as will be previewed in the widget gallery. I was also under the impression that placeholder is relevant in cases where the widget will be rendered on the home screen before data is available. In effect;

Snapshot - Should provide real data, asynchronously, but should return this data as quickly as possible for rendering in the widget gallery.

Placeholder - Should provide data as quickly as possible, synchronously, which will be (in a future beta) automatically rendered as redacted where relevant to provide a rendered UI.

Timeline - The standard timeline entries can be provided asynchronously, and as they do not need to be provided quickly (necessarily), can gather the relevant data from network resources or the app for optimal experience.

Do I have that right?
@brandonK212 where you able to get a sample of the differences between
Code Block
Snapshot
and
Code Block
Placeholder
  • I am having the same issue.