Meet WeatherKit at WWDC22
Meet WeatherKit at WWDC22
WWDC22: Key Takeaways from Meet WeatherKit
Data Provided
- Current weather
- Weather forecast: daily/hourly/minute granularity
- Wind direction and strength
- Sunrise/sunset phases and moon phases
- Historical weather data
- More details available in the documentation
Pricing Model (Platform State of the Union)
- Free for up to 500K calls/month
- Higher tiers available, e.g., 1M calls/month at $49.99
Free under 500k calls
Various plans available for higher traffic needs
It’s foreseeable that a multitude of weather apps will sprout up following this release.
Accessing WeatherKit with just a few lines of code:
import WeatherKit
import CoreLocation
let weatherService = WeatherService()
let syracuse = CLLocation(latitude: 43, longitude: -76)
let weather = try! await weatherService.weather(for: syracuse)
let temperature = weather.currentWeather.temperature
let uvIndex = weather.currentWeather.uvIndex
Apple also offers a method to call WeatherKit via RESTful API:
/* Request a token */
const tokenResponse = await fetch('https://example.com/token');
const token = await tokenResponse.text();
/* Get my weather object */
const url = "https://weatherkit.apple.com/1/weather/en-US/41.029/-74.642?dataSets=weatherAlerts&country=US"
const weatherResponse = await fetch(url, {headers: {"Authorization": token}});
const weather = await weatherResponse.json();
/* Check for active weather alerts */
const alerts = weather.weatherAlerts;
const detailsUrl = weather.weatherAlerts.detailsUrl;
Apple WeatherKit documentation:
https://developer.apple.com/documentation/weatherkit
By Marvin Lin on June 9, 2022.