-
Meet WeatherKit
WeatherKit offers valuable weather data for your apps and services to help people stay up to date on the latest conditions.
Learn how to use Swift and REST APIs to access information about the current weather, 10-day hourly forecasts for temperature, expected precipitation, wind reports, the UV Index, and more. We'll also share how WeatherKit can provide timely, hyperlocal weather information without compromising someone's personal data or their privacy.Recursos
Vídeos relacionados
Tech Talks
WWDC22
-
Buscar neste vídeo...
-
-
4:28 - Request the weather in Swift
// Request the weather 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 -
7:56 - Request the weather via REST 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;
-