I use a specific suiteName to send the data through UserDefaults, with my own key.
private func sendWeatherDataToWidget(input: CurrentDataConverted) {
let widgetData: WidgetWeatherData = WidgetWeatherData(theTemp: input.currentTemp,
theMax: input.dailyMaxTemp,
theMin: input.dailyMinTemp,
theTime: input.time,
theTempUnits: input.temperatureUnits,
theLocation: input.location)
let tempData = try! JSONEncoder().encode(widgetData)
UserDefaults(suiteName: "group.com.emkubed.Weewx-Weather")!.set(tempData,forKey: "Weewx-Weather")
WidgetCenter.shared.reloadTimelines(ofKind: "com.emkubed.Weewx-Weather")
logger.debug("Sent data to Widget - hopefully")
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: