Has anyone figured out the correct incantation of request parameters to get historic hourly weather conditions from WeatherKit? I've tried every combo of hourlyStart, dailyStart, currentAsOf, etc with past dates and it seems like the oldest it will go back to is midnight for today. I would like to get the last 24 hours of conditions.
WeatherKit
RSS for tagBring 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
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?
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.
I have added the WeatherKit capability and enabled it in the developer account for the respective app id. I continually get this error. Any ideas on how to fix this?
Failed to generate jwt token for: com.apple.weatherkit.authservice with error: Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors
Why does the documentation say this field returns the intensity of precipitation in UnitSpeed, this seems confusing. Shouldn't the amount of precipitation be an amount like inch/hr, mm/hr why would the value be in speed?
The old dark sky documentation for this field shows the units were returned in inches/hour
The weather data from Weather Kit REST API doesn't contain SF Symbol name.
Is there a way to get the SF Symbol name by "conditionCode"?
I am working on an app that pulls data from weatherKit, including the conditionCode property, the content of which is displayed to the user. I wish to localize the data pulled from weatherKit but when pulling data from:
weatherkit.apple.com/api/v1/weather/de/{latitude}/{longitude}
The conditionCode and other strings is in english. Same is true if the language parameter is set to es, ja or something else.
Am I doing something wrong or is localization yet to be supported in weatherKit? I can't find any documentation on this.
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))
I am able to obtain daily forecasts via the REST API which include the daytimeForecast and overnightForecast records with their respective properties like cloudCover.
So far I have failed to access them via the Swift API:
forecast.daytimeForecast.cloudCover
results in: "Value of type 'DayWeather' has no member 'daytimeForecast'".
But if I print() the DayWeather objects, these members are actually printed with all their properties.
Is there a way to get them I am overlooking?
Hello. I took a closer look at the data I'm getting back for hourly forecasts and I'm baffled by results I'm seeing.
For example, it's Dec 19, 2022 8:00am PT and I'm asking for the weather for Orchard Park NY (lat 42.766437 long -78.743855) for Dec 23, 2022. The daily forecast tells me they're expected to have 5.9" of snow. However, the hourly forecast with the most snow that day is reported as 0.071" (1.8mm). The Apple Weather app on iOS shows that hour as having 0.6".
I wrote a 'for' loop to print the results of my call to WeatherService.shared.weather.
print(oneHour.precipitationAmount.formatted())
print(oneHour.precipitationAmount.description)
print(oneHour.precipitationAmount.unit)
print(oneHour.precipitationAmount.value)
0.071 in
1.8 mm
<_NSStatic_NSUnitLength: 0x2010b0178> mm
1.8
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?
My pipeline broke today as new fields were added for the current weather dataset:
cloudCoverLowAltPct
cloudCoverMidAltPct
cloudCoverHighAltPct
I presumed new fields would only be released in a new version of the API? Is there any way to use a specific version of the API that will not be subject to change?
The current weather REST API docs are here, which don't include these fields: https://developer.apple.com/documentation/weatherkitrestapi/currentweather/currentweatherdata
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?
Is anyone else experiencing issues with the REST API today? I'm getting very slow response times (again.)
Next hour rain data is not available for US.
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)"
Hello - migrated from darksky to WeatherKit in April of this year. With some difficulty finally got the REST API to work via the following resources:
https://developer.apple.com/weatherkit/get-started/
which is horribly inadequate for JWT instructions. So i also used:
https://dev.iachieved.it/iachievedit/weatherkit-rest-api/
which was quite helpful.
As stated, in April i managed to get this working. About a week ago it stopped working.
The response from my calls are 401 Unauthorized in the header and { "reason": "NOT_ENABLED" } in the body.
I believe the key i created expired and thus WeatherKit stopped responding. So i tried to re-enable access using the same Apple key and a new JWT signature. That did not seem to work, so i removed the old key and created a new one. Downloaded the p8 file and used openssl on my ubuntu server to create pem and pub files for the jwt token. Still nothing. I have tried almost all combinations of keys and ID #s in the JWT.io console that i can think of.
Importantly, nowhere in the official Apple documentation does it say what parameters the key creation and expiry dates can be. Does the key creation date have to match the date the key was created in Apple Developer Console??? What expiry dates are valid???? No idea.
I have submitted a code level request, but they punted me to feedback which apparently does nothing. Still no resolution, nor have i been contacted once by an Apple representative. This is what my $200 developer fee gets me?! Unacceptable.
If anyone has any idea on how to resolve this issue and/or create valid jwt tokens easier (via PHP preferably), i'm all ears.
Thanks, airyt
What is the highest level of location precision achievable with the WeatherKit API? When latitude and longitude are given up to the fifth decimal place, the precision is around 1 meter. Could this ever be more accurate than providing the lat/long to the fourth decimal place, which has a precision of about 10 meters?
Could somebody please point me to the project download mentioned in Novall Khan’s “Meet Weatherkit” presentation?
I’d additionally or alternatively be interested in any working examples for using the rest API, eg in Python, to access Weatherki.
thanks,
Rob
I've received a forecast with non-zero precipitationChance and zero precipitationIntensity. Is this expected? How should I interpret the data?
{
"forecastStart": "2023-09-02T02:00:00Z",
"cloudCover": 0.55,
"conditionCode": "PartlyCloudy",
"daylight": false,
"humidity": 0.92,
"precipitationAmount": 0,
"precipitationIntensity": 0,
"precipitationChance": 0.31,
"precipitationType": "clear",
"pressure": 1017.56,
"pressureTrend": "steady",
"snowfallIntensity": 0,
"snowfallAmount": 0,
"temperature": 12.56,
"temperatureApparent": 12.22,
"temperatureDewPoint": 11.26,
"uvIndex": 0,
"visibility": 23505.2,
"windDirection": 233,
"windGust": 6.17,
"windSpeed": 2.82
}