WeatherKit - Forecast Issue Time

Hi There, My app displays both daily and hourly forecast information, as consumed from the Weatherkit API.

I would also like to let my users know when the forecast was generated/issued. The reason being, if a forecast was issued 1-2 hours in the past for example, then the user(s) will know to refresh the weather forecast for the latest information soon.

Looking through the docs, I don't see any way of accessing this information. I would expect it to be available on the hourlyForecast.metadata property.

Does anyone know if it's possible to obtain the 'issued time' of the forecast? (both hourly and daily).

Thanks

Answered by in 821132022

The response metadata contains a few fields that would help make this decision.

  • readTime - The time at which the response data was read from WeatherKit.
  • reportedTime - The time at which the source data was made available from the data provider. For the daily and hourly forecasts this is the time that the global weather model was run and all the data from which we built the response was made available. This is likely the value you are asking about.
  • expireTime - This tells you (and your users) when the forecast information should be refreshed.

Our recommendation would be to just use expireTime to determine when the data is due to be refreshed rather than estimating it yourself.

Accepted Answer

The response metadata contains a few fields that would help make this decision.

  • readTime - The time at which the response data was read from WeatherKit.
  • reportedTime - The time at which the source data was made available from the data provider. For the daily and hourly forecasts this is the time that the global weather model was run and all the data from which we built the response was made available. This is likely the value you are asking about.
  • expireTime - This tells you (and your users) when the forecast information should be refreshed.

Our recommendation would be to just use expireTime to determine when the data is due to be refreshed rather than estimating it yourself.

Thanks for the info - I am however struggling to find the properties you mention above. What am I missing here? I am using the Swift WeatherService() to obtain the weather forecast per below.

let weather = try await weatherService.weather(for: location)

On the weather object, I see hourlyForecast, dailyForecast, currentWeather, availability. But no metadata property. I do see the metaData property on currentWeather, which includes the fields date, expirationDate, location.

Thanks a lot

WeatherKit - Forecast Issue Time
 
 
Q