WeatherKit UV index is always returning 0

Hi, i've been playing with WeatherKit for the first 3 betas but each time I try to get the UV Index of a forecast I've got 0 as value. For example the hourly forecast of San Francisco at the time of writing is the following :

Optional(WeatherKit.HourWeather(date: 2022-07-06 14:00:00 +0000, cloudCover: 0.98, condition: Drizzle, symbolName: "cloud.moon.rain", dewPoint: 21.87 °C, humidity: 0.95, isDaylight: false, precipitation: rain, precipitationChance: 0.44, precipitationAmount: 0.44 mm, snowfallAmount: 0.0 mm, pressure: 1000.93 mbar, pressureTrend: Steady, temperature: 22.67 °C, apparentTemperature: 24.89 °C, uvIndex: WeatherKit.UVIndex(value: 0, category: Low), visibility: 8977.97 m, wind: WeatherKit.Wind(compassDirection: South Southeast, direction: 151.0 °, speed: 32.34 km/h, gust: Optional(48.66 km/h))))

While the UV Index at the time from The Weather Network is supposed to be 4. I've got this issue since beta 1 and it's happening on every location I try.

Is this happening as well to other people ? Is there anything on my side in term of configuration that I should do ?

Replies

I think it may be a timezone issue. Note "cloud.moon.rain" - moon is a clue that it thinks it's night. Oh, and "isDaylight: false". The time shown is 14:00 +0000. That should surely be 14:00 +0800. (Or is it -0800, I'm never sure about that...)

  • It's a good clue because i'm currently fetching this weather from France where it's the night. I'll try to check with Paris forecast tomorrow during the day to see if it's also happening. Thanks !

Add a Comment

Ok so i've made a few changes to the code to use the real location and change it on the simulator level + use .current WeatherQuery to fetch weather :

func fetchUVIndex(location: Location) async throws -> Int {
    let clLocation = CLLocation(latitude: location.latitude, longitude: location.longitude)
    let weather = try? await self.weatherService.weather(for: clLocation, including: .current)

    guard let weather else { throw UVError.noWeatherAvailable }

    return weather.uvIndex.value
}

Now it's working fine and returning the correct value