WeatherKit

RSS for tag

Bring weather information to your apps and services through a wide range of data that can help people stay up to date, safe, and prepared.

Posts under WeatherKit tag

67 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

WeatherKit REST API parameter validation inconsistency
The status codes returned for REST API queries give a good indication of the issue encountered. Generally: 200 is good 400 means you've passed in bad or incomplete parameters 401 is an authentication issue However, there's a parameter validation inconsistency on the availability endpoint. If you pass in out-of-range coordinates to the weather endpoint, you get the expected 400 response code. But if you pass bad coordinates to the availability endpoint, it blows up and returns a 500 (internal server error). I've got code that can deal with this response, but it would be much better to know exactly where the problem lies. 500 tells me there's an issue on the server that's out of my control...
1
0
371
Dec ’23
WeatherKit: Couldn't lookup symbols
I'm not able to inspect WeatherKit objects like HourWeather and CurrentWeather using the Xcode debugger and breakpoints. When I pause on a breakpoint and try something like po hours where hours is a [HourWeather] I get a debugger error like Couldn't lookup symbols: type metadata accessor for WeatherKit.HourWeather. Is there something about WeatherKit that prevents the debugger from printing out its objects?
1
1
668
Nov ’23
WeatherKit symbol for single location.
Hello, I'm using WeatherKit in a project to display the SF Symbol for the weather in the app toolbar. I have this for the WeatherModel: import Foundation import WeatherKit @MainActor class WeatherManager: ObservableObject { @Published var weather: Weather? public func getWeather() async { do { weather = try await Task.detached(priority: .userInitiated) { return try await WeatherService.shared.weather(for: .init(latitude: 28.3772, longitude: -81.5707)) }.value } catch { fatalError("\(error)") } } var symbol: String { weather?.currentWeather.symbolName ?? "xmark.icloud.fill" } var temp: String { let temp = weather?.currentWeather.temperature let convert = temp?.converted(to: .fahrenheit).description return convert ?? "" } } And this in the SwiftUI View: ToolbarItem(placement: .topBarLeading) { @ObservedObject var weatherManager = WeatherManager() Image(systemName: weatherManager.symbol) .task { await weatherManager.getWeather() } } But when I build and run the app on my phone it displays the "xmark.icloud.fill" instead of the actual weather. Did I do something wrong?
0
0
402
Nov ’23
WeatherKit REST API Invalid Signature (php)
I'm trying to make a PHP implementation to fetch data from the WeatherKit REST API. When using jwt.io to create a JWT, everything works correctly, so my keys, identifiers, etc. are set up correctly. When using jtw.io to verify my own generated JWT, the header and payload are correct, but "Invalid Signature" is displayed. The file path for the private key exists and the file is loaded correctly. My PHP code: function generate_jwt(): String { $tmpFilePath = realpath(dirname(__FILE__)).'/'; $filePath = $tmpFilePath.'../AuthKey.pem'; //$filePath = $tmpFilePath.'../AuthKey.p8'; $private_key = NULL; if (file_exists($filePath)) { $private_key = file_get_contents($filePath); } $header = [ "alg" => "ES256", "kid" => "XXXXXXXXXX", "id" => "YYYYYYYYYY.com.thing.stuff", "typ" => "JWT" ]; $header = $this->base64_url_encode(json_encode($header)); $issuedAt = time(); $payload = [ "iat" => $issuedAt, "exp" => $issuedAt + 30, "iss" => "YYYYYYYYYY", "sub" => "com.thing.stuff" ]; $payload = $this->base64_url_encode(json_encode($payload)); $signature = $this->base64_url_encode(hash_hmac('sha256', "$header.$payload", $private_key, true)); $jwt = "$header.$payload.$signature"; return $jwt; } function base64_url_encode($text): String { return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($text)); } Any ideas?
0
0
434
Nov ’23
WeatherKit Historical Data Request Limited to 10 Days
Until recently, I was unable to use WeatherKit to obtain historical Daily data. Now, it appears that I can retrieve Daily and Hourly historical data, but the returned data is limited to a ten day period. No matter what start and end dates are included, I get data from start date to 10 days later (assuming the end date was more than 10 days after the start). Is this a permanent restriction? Example: let historicalData = try await weatherService.weather(for: location, including: .daily(startDate: startDate, endDate: endDate))
2
1
1.4k
Nov ’23
REST API returns 404 error for October 29th
In my app I retrieve the daily weather for a location via the REST API. This works fine in almost all cases. However, for October 29th (yesterday) it returns a 404 Not Found error. This is an example request that fails: https://weatherkit.apple.com/api/v1/weather/en/48.1582271841334/11.5418646663957?dataSets=forecastDaily&dailyStart=2023-10-28T22:00:00.0000000Z&dailyEnd=2023-10-29T22:00:00.0000000Z I have also tried to append the timezone &timezone=Europe/Berlin - but the problem persists. Maybe it has to do with the fact that Daylight saving time ended yesterday at the location requested (Germany)? It certainly looks like a bug. Where can I report it if this isn't the right place to do so?
0
0
361
Oct ’23
Weather forecast one day short
Using WeatherKit I want to get a 5-day forecast starting tomorrow, however, I only get 4 elements in the forecast. What am I missing here? public func updateWeather()async{ guard locationManager.location != nil else {locationManager.updateLocation(); return} if self.needsUpdating{ let startOfToday = Calendar.current.startOfDay(for: Date()) let endOfToday = startOfToday+24*3600 let firstDay:Date = endOfToday+1 let lastDay:Date = firstDay+(5*24*3600) futureWeather = try? await WeatherService.shared.weather(for: locationManager.location!, including: .daily(startDate: firstDay, endDate: lastDay) ) } }
2
0
463
Oct ’23
Weather Kit is not returning historical data
I'm trying to get historical data using the following syntax: try await service.weather(for: location, including: .daily(startDate: past1, endDate: past2)) Where past1 and past2 are two dates in the past (I checked their format and they are correct). I always get the same result, namely the 10 days default forecast you usually get calling service.weather(for: location) Am I missing something?
4
3
1.5k
Oct ’23
WeatherKit Historical Averages
Is there a means of accessing historical averages from WeatherKit? I imagine it would be monthly averages. Apple's Weather app recently introduced "Averages" – both daily and monthly. I'm wondering if this data is derived from WeatherKit. I'm also curious if there exists an API available to developers that hasn't made its way into the documentation yet, or if there are plans for making "averages" available to developers in upcoming improvements to WeatherKit.
0
2
336
Oct ’23
WeatherKit Apple Weather trademark and legal link.
I have read the WeatherKit docs and watched the "Meet WeatherKit" WWDC video but it is not clear where the trademark and legal link need to be displayed. Can someone at Apple please clarify this. The docs state: "If your apps, web apps, or websites display any Apple weather data, you must clearly display the Apple Weather trademark, as well as the legal link to other data sources." I have a calendar style app on the App Store and want to incorporate weather data as simple icons into the day, week, month views with in the app. Is it ok to just display the trademark and legal link in the app's Settings view where a user would first turn on this weather feature? Or does it have to be displayed on every single view where weather data is displayed? Even if that data is just displaying a simple Sun or Cloud or Rain symbol to the user. Thanks.
3
3
1.8k
Oct ’23
Location Permission Message Not Appearing
This is a app for weather in which i used weatherkit.I have added "privacy - Location when in Usage Description in info of project and also enabled location in features of simulator to Apple.After doing all this ,still the permission message for location is not appearing in app in simulator.Following is my code: import CoreLocation import UIKit //final means this class will not be subclassed final class ViewController: UIViewController, CLLocationManagerDelegate { let locationManager = CLLocationManager() //to access weather data let service = WeatherService() override func viewDidLoad() { super.viewDidLoad() setupView() getUserLocation() } func getUserLocation(){ locationManager.delegate = self locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() } func getWeather(location : CLLocation){ //asynchoronus task Task { do { //if it throws error //await tells to wait until function gives results let result = try await service.weather(for: location) print("Current : "+String(describing: result.currentWeather)) print("Daily : "+String(describing: result.dailyForecast)) print("Hourly : "+String(describing: result.hourlyForecast)) } catch { //it will be excecuted print(error.localizedDescription) } } } func setupView(){ } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { guard let location = locations.first else { return } locationManager.stopUpdatingLocation() getWeather(location: location) } func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { switch status { case .denied: print("location permission denied") case .authorizedWhenInUse, .authorizedAlways : manager.startUpdatingLocation() print("Location Permission Granted") case .notDetermined : print("location Permission not determined") default: break } } }
0
0
380
Oct ’23
WeatherKit error on iOS 17 - macOS 14
Hi I upgraded my Mac to test the new os and iOS 17. But I have problems with the weather kit on the app. WeatherKit enabled as app service and capability there was no issue with the iOS 16. What could be the problem? import Foundation import WeatherKit class WeatherKitManager: ObservableObject { @Published var weather: Weather? @Published var isFetchingWeather = false func getWeather(latitude: Double, longitude: Double) async { do { let receivedWeather = try await WeatherService.shared.weather(for: .init(latitude: latitude, longitude: longitude)) DispatchQueue.main.async { self.weather = receivedWeather } } catch { fatalError("\(error)") } } var symbol: String { weather?.currentWeather.symbolName ?? "xmark.app" } var temp: String { if let temp = weather?.currentWeather.temperature.converted(to: .celsius) { let formattedTemp = String(format: "%.1f", temp.value) return "\(formattedTemp)°C" } else { return "Yükleniyor..." } } } Errors here Ceyehat/WeatherKitManager.swift:22: Fatal error: Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors Code=2 "(null)" Failed to generate jwt token for: com.apple.weatherkit.authservice with error: Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors Code=2 "(null)" Encountered an error when fetching weather data subset; location=<+37.78583400,-122.40641700> +/- 0.00m (speed -1.00 mps / course -1.00) @ 06/06/2023, 5:32:55 PM GMT+03:00, error=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors 2 Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors Code=2 "(null)"
23
7
4.6k
Oct ’23
WeatherKit Historical Data
Hi, We have been using DarkSky's API for a few years now and we've always been able to pull data for at least 3 years prior to the current date. With WeatherKit, we are seeing that data is only available for the last 2 years. I've seen a few posts confirming this, but I'm curious if we will always be limited to 2 years of data or if this is a temporary situation and as time goes on, WeatherKit will have more and more historical data available? Another way to put it is will Apple always delete any data older than 2 years or will they start to build up an archive so in 10 years from now, they will have 12 total years of data (given they have 2 years right now). Thanks!
1
0
517
Sep ’23
WeatherKit Preflight Check fails
I created my own service to generate a JWT for WeatherKit. When I use this JWT in Postman it works as expected. However, if I use it in my React application I get a 403 CORS pre-flight check error. What this essentially means is by nature, Safari - before doing the GET call with Authorization header - it does a preflight check OPTIONS call without headers, to check if the service will accept the request. Unfortunately this generates a 403 error instead of an 200, so the GET Call with Authorization header cannot be made. Is this by design to prevent webfrontends from accessing the API or is this a bug I encountered? Thank you!
0
0
416
Sep ’23