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.

WeatherKit Documentation

Posts under WeatherKit tag

37 Posts
Sort by:
Post not yet marked as solved
2 Replies
154 Views
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.
Posted
by
Post marked as solved
1 Replies
180 Views
I'm trying out weather kit and I'm using swiftUI I have a view that accepts a CurrentWeather type value in initailizer I cannot find a way to initialize a CurrentWeather How can I preview It? This won't work: // forecaster and forecast is defined by me struct WeatherView_Previews: PreviewProvider {     static var previews: some View { // <- static WeatherView(weather: await forecaster.forcast(latitude: 0, longtitude: 0)) // <- concurrency     } }
Posted
by
Post not yet marked as solved
2 Replies
135 Views
We are currently using the DarkSky API for energy forecasting, and one important piece of data is the solar DNI. With DarkSky we could set the solar parameter to true and we would get this data: "solar": { "azimuth": 275, "altitude": 30, "dni": 677.1, "ghi": 369.1, "dhi": 33.6, "etr": 1318.8 } The WeatherKit API does not appear to have this parameter. Does anyone know if it will have this solar data eventually? It will impact whether we can use the API or not.
Posted
by
Post marked as Apple Recommended
231 Views
When I fetch weather for my location and print the raw Weather response to the console, airQualityAvailability is set to available in availability. And alongside currentWeather, dailyForecast, hourlyForecast, and minuteForecast, there is also an airQuality object that contains a lot of information. I cannot figure out how to access this data through dot notation on the Weather response, and I cannot find any mention of air quality data in the documentation. How can I access this AQI information? Or is it planned but not yet officially accessible? Best, Michael
Posted
by
Post not yet marked as solved
1 Replies
266 Views
Hi all, I am trying to use the WeatherKit REST API but when I try to register an app, I don't see WeatherKit as an available services that I can select under the App Services Tab. How do I get access to the WeatherKit service? Thanks,
Posted
by
Post marked as solved
1 Replies
189 Views
Hello Everyone, In the example code, I'm trying to convert from Fahrenheit to Celsius, but I'm not succeeding. Output is always in Fahrenheit. My code is this:   func formattedTemperature(_ temp: Measurement<UnitTemperature>) -> String {         let tempC = temp.converted(to: .celsius)         return tempC.formatted(.measurement(width: .abbreviated, usage: .weather))     } In the simulator I also went into the settings and switched in General->Language/Region from F to C. But this also had not effect. Would anyone have an idea how to correct this? Thanks and best regards, Patrick
Posted
by
Post marked as solved
2 Replies
247 Views
I'm trying to access this element of the HourWeather retrieved from a call to weatherService. When I print in the debugger what is received, it's clear that there is an element there called precipitationAmount. Here is an example of everything retrieved in HourWeather for a particular hour: HourWeather(date: 2022-06-12 22:00:00 +0000, cloudCover: 0.46, condition: Breezy, symbolName: "wind", dewPoint: 9.12 °C, humidity: 0.71, isDaylight: true, precipitation: rain, precipitationChance: 0.23, precipitationAmount: 0.21 mm, snowfallAmount: 0.0 mm, pressure: 997.65 mbar, pressureTrend: Rising, temperature: 14.34 °C, apparentTemperature: 13.74 °C, uvIndex: WeatherKit.UVIndex(value: 1, category: Low), visibility: 25915.82 m, wind: WeatherKit.Wind(compassDirection: Northwest, direction: 304.0 °, speed: 29.47 km/h, gust: Optional(41.56 km/h))) But when I try to access that element as part of a SwiftUI view in Xcode (14.0 beta), I get this error: Value of type 'HourWeather' has no member 'precipitationAmount' Furthermore, that element is not listed as part of the documentation at https://developer.apple.com/documentation/weatherkit/hourweather, which is presumably the reason for the Xcode error. But it's there in what is retrieved, so how can I access it? Forgive me if this is a noob question - I'm not an expert SwiftUI programmer. Thanks ... Neil
Posted
by
Post not yet marked as solved
1 Replies
182 Views
If you use the iOS16 Swift WeatherKit API you can get the weather data attribution logo doing something like: // Skipping full syntax for example let attribution = WeatherService.shared.attribution // A URL to an image you can show along with the weather data attribution.combinedMarkLightURL What about if you are not using the iOS16 WeatherKit wrappers e.g. you are using the REST API on your own server to return data. The API docs show a providerLogo/providerName parameter in the metadata returned from the service, but they don't seem to be populated right now. Is it ok just to use a unicode Apple logo to make a string instead like:  Weather Also in the API there is a metadata object returned in each dataset e.g. current, daily, hourly which each has an attributionURL field, will all those values always be the same or we might have to display multiple URLs for data sources, the Swift example seems to just have one attribution object.
Posted
by
Post not yet marked as solved
2 Replies
321 Views
I have upgraded from macOS 12.5.4 to macOS 13 Beta 1. Haven't done anything odd. I am attempting to use WeatherKit but I am getting a lot of (odd) errors: The sample can't access the ~/Library/Weather/ folder despite it being set to read for users, others and group. (I've since switched to read and write for all, but no dice). Lots of other odd errors. 2022-06-11 22:52:26.720487+0100 PlayWithWeatherKit[16282:277975] [WeatherService] Couldn't get access to the /Library/Weather directory for the geocode Store. error=Error Domain=NSCocoaErrorDomain Code=257 "The file “Weather” couldn’t be opened because you don’t have permission to view it." UserInfo={NSUserStringVariant=(     Folder ), NSURL=file:///Users/tarasis/Library/Weather, NSFilePath=/Users/tarasis/Library/Weather, NSUnderlyingError=0x6000013d4b70 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} PlayWithWeatherKit[16282:277975] [] networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception. PlayWithWeatherKit[16282:277975] [] networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception. PlayWithWeatherKit[16282:277975] [WeatherDataService] Failed to create the weather data store, error=cantOpen(message: "authorization denied", location: TeaDB.Database.Location.path("/Users/tarasis/Library/Weather/weather-data.db")) PlayWithWeatherKit[16282:277991] [Metadata] unable to get a dev_t for store 1795162192. PlayWithWeatherKit[16282:277991] [] nehelper sent invalid response: <dictionary: 0x1ffa87480> { count = 1, transaction: 0, voucher = 0x0, contents = "XPCErrorDescription" => <string: 0x1ffa87618> { length = 18, contents = "Connection invalid" } } PlayWithWeatherKit[16282:277991] [] nw_parameters_set_source_application_by_bundle_id_internal Failed to convert from bundle ID (net.tarasis.test.wwdc.Playground) to UUID. This could lead to wrong data usage accounting. PlayWithWeatherKit[16282:277991] [connection] nw_endpoint_flow_validate_delegation [C1 weather-data.apple.com:443 in_progress parent-flow (satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns)] Network Delegation Failure: Invalid Bundle ID "net.tarasis.test.wwdc.Playground" [M] PlayWithWeatherKit[16282:277991] [] nw_resolver_can_use_dns_xpc_block_invoke Sandbox does not allow access to com.apple.dnssd.service PlayWithWeatherKit[16282:277991] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:14 Err:-1 Errno:1 Operation not permitted PlayWithWeatherKit[16282:277991] [connection] nw_resolver_create_dns_service_locked [C1.1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563) PlayWithWeatherKit[16282:277991] Connection 1: received failure notification PlayWithWeatherKit[16282:277991] Connection 1: failed to connect 10:-72000, reason -1 PlayWithWeatherKit[16282:277991] Connection 1: encountered error(10:-72000) PlayWithWeatherKit[16282:277975] Task <0D654665-D88F-4C81-ABDA-FBFAAC0B01E5>.<1> HTTP load failed, 0/0 bytes (error code: -1003 [10:-72000]) PlayWithWeatherKit[16282:277975] Task <0D654665-D88F-4C81-ABDA-FBFAAC0B01E5>.<1> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x6000013b0060 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns, _kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <0D654665-D88F-4C81-ABDA-FBFAAC0B01E5>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(     "LocalDataTask <0D654665-D88F-4C81-ABDA-FBFAAC0B01E5>.<1>" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://weather-data.apple.com/v2/token, NSErrorFailingURLKey=https://weather-data.apple.com/v2/token, _kCFStreamErrorDomainKey=10} PlayWithWeatherKit[16282:277975] [WeatherService] Encountered an error when fetching weather data subset; location=<+37.32299800,-122.03218100> +/- 0.00m (speed -1.00 mps / course -1.00) @ 2022/06/11, 22:52:26 British Summer Time,  error=Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x6000013b0060 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns, _kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <0D654665-D88F-4C81-ABDA-FBFAAC0B01E5>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(     "LocalDataTask <0D654665-D88F-4C81-ABDA-FBFAAC0B01E5>.<1>" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://weather-data.apple.com/v2/token, NSErrorFailingURLKey=https://weather-data.apple.com/v2/token, _kCFStreamErrorDomainKey=10}
Posted
by
Post not yet marked as solved
1 Replies
257 Views
In the Meet WeatherKit video it is stated that "You can access historical data by specifying a start and end date to the hourly and daily requests.", but I'm not seeing a way to do that in the Swift API (I see it is there in the REST API). Am I missing something or is that just not implemented yet?
Posted
by
Post not yet marked as solved
4 Replies
228 Views
Hi, I am getting and invalidJWTResponse when using WeatherKit Swift API, I have setup everything correctly including enabling WeatherKit in both Capabilities and App Services, Added WeatherKit" to Xcode Capabilities, and waited for more than one day! But still it's not working! invalidJWTResponse(Optional(<NSHTTPURLResponse: 0x6000008d8300> { URL: https://weather-data.apple.com/v2/token } { Status Code: 401, Headers {     Connection =     (         close     );     "Content-Length" =     (         0     );     Date =     (         "Thu, 09 Jun 2022 18:24:24 GMT"     );     Server =     (         "AppleHttpServer/5712591c84160e0cbbf19c8f434c32ab02f2a7f4"     );     "Strict-Transport-Security" =     (         "max-age=31536000"     );     "X-Apple-Origin" =     (         "01ca7adc-14e8-31f5-9654-4375b40868e2"     );     "X-B3-TraceId" =     (         795fbfea426330d9     );     "X-Cache" =     (         "TCP_MISS from a88-221-161-85.deploy.akamaitechnologies.com (AkamaiGHost/10.8.2-41841244) (-)"     );     "X-REQUEST-ID" =     (         "3e6d21c8-ffa0-4c56-aa91-8466619a4993"     ); } }))
Posted
by
Post not yet marked as solved
0 Replies
146 Views
The documentation lists the number of calls per month you can make for the different pricing tiers here: https://developer.apple.com/weatherkit/get-started/ but are there going to be any per second/minute/hour rate limits on calls to the API like with other weather service APIs. For example maybe you get 1,000,000 calls per month but there is some limit like 5 calls per second or 10,000 calls per hour imposed by the APIs? Also what happens if you go over your allowed call limit for the month, will the API just return an error like HTTP 402 or you will get a warning for a period of time? Would you be able to buy extra calls for the month without having to upgrade to a new tier, assuming maybe you are experiencing a temporary increase in traffic.
Posted
by
Post marked as solved
25 Replies
2k Views
I'm following along to the WWDC WeatherKit session, and I keep getting this 401 network error that causes my app to crash on a fatal error. I have already created the proper Bundle App ID with WeatherKit enabled, and added the WeatherKit capability. Here is my code: private func getWeather() async -> Double {         let weatherService = WeatherService()         let syracuse = CLLocation(latitude: 33.6846, longitude: 117.8265)         let weather = try! await weatherService.weather(for: syracuse)         let temperature = weather.currentWeather.temperature         return temperature.converted(to: .celsius).value     } Full error message: 2022-06-07 17:35:43.051776-0700 WWDC2022[56529:1296409] WWDC2022/WeatherView.swift:30: Fatal error: 'try!' expression unexpectedly raised an error: WeatherDaemon.WDSHMACJWTAuthenticatorService.Errors.invalidJWTResponse(Optional(<NSHTTPURLResponse: 0x6000018402c0> { URL: https://weather-data.apple.com/v2/token } { Status Code: 401, Headers {     Connection =     (         close     );     "Content-Length" =     (         0     );     Date =     (         "Wed, 08 Jun 2022 00:35:43 GMT"     );     Server =     (         Apple     );     "Strict-Transport-Security" =     (         "max-age=31536000; includeSubdomains"     );     "X-Apple-Origin" =     (         "8961098f-b238-3714-ba44-5b569c861456"     );     "X-Cache" =     (         "TCP_MISS from a23-219-38-54.deploy.akamaitechnologies.com (AkamaiGHost/10.8.2-41841244) (-)"     );     "X-Content-Type-Options" =     (         nosniff     );     "X-Frame-Options" =     (         SAMEORIGIN     );     "X-REQUEST-ID" =     (         "5156c5c7-d23b-4a66-a161-c8a9fb849c85"     );     "X-XSS-Protection" =     (         "1; mode=block"     ); } }))
Posted
by
Post not yet marked as solved
0 Replies
239 Views
To anyone it may help, I've put together an OpenAPI spec of the WeatherKit REST API, which you may find useful for client generation using one of the OpenAPI generators. https://github.com/vanshg/WeatherKit-OpenAPI
Posted
by
Post not yet marked as solved
1 Replies
243 Views
Hi - I don't see anything in the documentation about which regions of the world the API will support e.g. US, Europe. I see there is an /api/v1/availability you can call but is there some rough guidelines around what areas are supported and which aren't. Thanks Mark.
Posted
by
Post not yet marked as solved
13 Replies
1.4k Views
Hi there! Please could you publish some of the specifics for authentication for the new WeatherKit REST API? I am attempting to use something cobbled together from MapKit, and unfortunately WeatherKit returns a 500 error in response. Broken code sample below. If you find a working solution or can identify an error, please comment with the solution. Thank you! require 'http' require 'jwt' require 'openssl' require 'logger' p8 = OpenSSL::PKey::EC.new(File.read("/PATH/TO/DOWNLOADED/P8/FILE")) token = JWT.encode({ iss: 'KEY_NAME_FROM_CIP', iat: Time.now.to_i, exp: Time.now.to_i + 3600, aud: 'weatherkit', }, p8, 'ES256', { kid: 'KEY_ID_FROM_CIP', typ: 'JWT' }) res = HTTP.use(logging: { logger: Logger.new(STDOUT) }).headers( "Authorization" => "Bearer #{token}" ).get "https://weatherkit.apple.com/api/v1/weather/en/LONG/LAT?dataSets=currentWeather&timezone=Europe/London" puts "code: #{res.code}" puts res.body
Posted
by