Post not yet marked as solved
WeatherKit has been returning 404 errors for the last four hours without any successful requests. Is anyone else receiving this issue?
Post not yet marked as solved
For some reason this morning (5 December 2023, ~10:30am UTC) I have been experiencing intermittent WeatherKit API failures with a 404 Not Found status.
There is nothing wrong with the request itself: trying a minute or two later with the exact same request parameters and token returns a successful response.
I can see that it's not a transport issue between me and Apple, as the response I am getting is coming from the Apple servers:
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<center><h1>404 Not Found</h1></center>
<hr>
<center>Apple</center>
</body>
</html>
...and the responding server is AppleHttpServer.
Has anyone else seen this? Is it a regular occurrence, or are they just having a bad day?
Post not yet marked as solved
Yet another day yet another WeatherKit outage it seems.
We have been getting 404s on WeatherKit requests for the past 1.5 days, across a number of different lat/lngs and times. Not all requests are failing and we have confirmed that we are well below our allocated quota per our subscription tier.
Anyone else experiencing similar issues?
Post not yet marked as solved
When I'm using the following code into the simulator it gives the wanted result:
Button {
Task {
localWeather = try await WeatherService.shared.weather(for: CLLocation(latitude: 52.5153, longitude: 6.08565), including: .daily(startDate: Date(), endDate: Calendar.current.date(byAdding: .day, value: 1, to: Date())!)).first.debugDescription
}
} label: {
Text("Get the test weather")
}
Text(localWeather)
When I'm using this exact code on a real device I get the following 404 error:
[WeatherDataService] Received invalid http response code 404 for request: C7AEC7CC-E5F7-425D-8491-25B9302E2A0F:0
[WeatherService] Encountered an error when fetching weather data subset; location=<+52.51530000,+6.08565000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 05/01/2023, 13:55:53 Central European Standard Time, error=responseFailed(<NSHTTPURLResponse: 0x282ce0260> { URL: https://weather-data.apple.com/v3/weather/en/52.515/6.086?timezone=Europe/Amsterdam&dataSets=forecastHourly,forecastDaily&dailyStart=2023-01-10T12:00:00Z&dailyEnd=2023-01-10T12:00:00Z&hourlyStart=2023-01-10T11:00:00Z&hourlyEnd=2023-01-10T16:00:00Z&country=NL } { Status Code: 404, Headers {
"Access-Control-Allow-Origin" = (
"*"
);
"Cache-Control" = (
"max-age=0, no-cache, no-store"
);
Connection = (
"keep-alive"
);
"Content-Length" = (
0
);
"Content-Security-Policy" = (
"default-src 'self';"
);
Date = (
"Thu, 05 Jan 2023 12:59:27 GMT"
);
Expires = (
"Thu, 05 Jan 2023 12:59:27 GMT"
);
Pragma = (
"no-cache"
);
Server = (
"AppleHttpServer/21be5247c6351682d1d9aa22fe98c8f0d4902838"
);
"Strict-Transport-Security" = (
"max-age=31536000; includeSubDomains",
"max-age=31536000"
);
"X-Apple-Origin" = (
"bcd49c7f-c567-3921-a041-3d4ef58e5423"
);
"X-B3-TraceId" = (
c8c6547722afc53f
);
"X-Cache" = (
"TCP_MISS from a104-110-190-91.deploy.akamaitechnologies.com (AkamaiGHost/10.10.3-45298580) (-)"
);
"X-Content-Type-Options" = (
nosniff
);
"X-Frame-Options" = (
DENY
);
"X-REQUEST-ID" = (
"407e37bc-ddf6-45fd-84d0-1d3d3b8651b0"
);
"X-XSS-Protection" = (
"1; mode=block"
);
} }, Optional(""))
I fixed it once by deleting Xcode and the app from my iPhone, but that doesn't work anymore.
Any suggestions?
Post not yet marked as solved
For locations in timezones East of me the returned results start at yesterday, Today is Saturday, the results start at Friday. Sometimes results can start 2 gays ago. Locations in my timezone and those west do not behave this way; the results start at Saturday.
I'm doing the most basic request:
self.weather = try await weatherService.weather(for: CLLocation(latitude: location.latitude, longitude: location.longitude) )
My understanding this returns 10-days of forecast.
What is going on?
I need to know if the results are appropriate for the days returned. IE. Is today's forecast for tomorrow, today or yesterday?
Any guidance is appreciated.
Kirk Mahr
Post not yet marked as solved
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...
Post not yet marked as solved
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?
Post not yet marked as solved
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?
Post not yet marked as solved
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?
When retrieving data using WeatherKit, a CLLocation is passed. What is the range / span of that data? In other words: at what distance to the given location is the returned weather data valid?
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))
Post not yet marked as solved
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?
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)
)
}
}
Post not yet marked as solved
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?
Post not yet marked as solved
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.
Post not yet marked as solved
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.
Post not yet marked as solved
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
}
}
}
Post not yet marked as solved
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)"
Post not yet marked as solved
Next hour rain data is not available for US.
Post not yet marked as solved
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!