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

200 Posts

Post

Replies

Boosts

Views

Activity

Hourly history with WeatherKit REST API
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.
11
4
6.2k
Aug ’23
WeatherKit REST API 401 Unauthorized {reason:NOT_ENABLED}
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
1
1
1.4k
Aug ’23
WeatherKit Location Precision
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?
0
2
817
Aug ’23
WeatherKit Swift / REST mismatch? daytimeForecast and overnightForecast not available via Swift?
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?
2
0
2.0k
Jul ’23
Use WeatherKit in an Xcode playground?
Can it be done? I can reliably crash Xcode by attempting the following in a playground: import UIKit import WeatherKit import CoreLocation let sanFrancisco = CLLocation(latitude: 37.7749, longitude: 122.4194) let weatherService = WeatherService() let weather = try await weatherService.weather(for: sanFrancisco) let temperature = weather.currentWeather.temperature print(temperature) Xcode 14.3.1 macOS 13.4.1
8
1
1.8k
Jul ’23
WeatherKit in a background operation?
Sorry if this is a stupid question but I haven't been able to find any information on whether an app can request and receive weatherKit data - the weather - while in the background. My app (AirCompare) makes extensive use of background URL sessions to fetch and process weather data. If certain conditions are met, a notification alert is sent to the user so the user can decide whether to activate the app. For instance if rain is in the forecast, the app alerts the user that they might want to close their windows. Making the app active will execute HomeKit control and accomplish that. Will I be able to replace the background URL session with the appropriate code and be able to fetch weather data in the background?
2
0
1.3k
Jul ’23
Cannot infer contextual base in reference to member 'fractionLength'
I am trying to format a measurement in my application as described in this documentation. Notice the example code: let temp = Measurement<UnitTemperature>(value: 38, unit: .celsius) let formattedTemp = temp.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1)))) // For locale: en_US: 100.4 degrees Fahrenheit When I try to do the same, I receive the following errors: Cannot infer contextual base in reference to member 'fractionLength' Cannot infer contextual base in reference to member 'numeric' Extra argument 'numberFormat' in call My code is as follows: Text("\(current.temperature.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1)))))") Where current is a CurrentWeather type provided by WeatherKit. Why is my adherence to the documentation causing these errors?
1
0
1.2k
Jul ’23
Does Weatherkit have a webhook for push notifications?
I'm implementing PUSH NOTIFICATIONS for an app that uses Weatherkit ("there is a Tornado outside your house, run!") I enabled the capability, the code in app delegate, tested the push notification with the new apple console. and everything WORKS, BUT...how can I receive push notifications from Weather kit? do they have a webhook that I can listen to? I cannot find anything in the documentation. https://developer.apple.com/documentation/weatherkitrestapi/get_api_v1_weatheralert_language_id or do I need to create a server to call weatherkit every min? I don't understand how to listen to weather kit for alerts. thanks
1
1
904
Jun ’23
Weatherkit Rest API returns 401 if JWT timestamp is off by 10 minutes
I am using the Weatherkit Rest API successfully for Android. But I noticed that when I create a JSON Web Token with a timestamp for Issued at (iat) which is off by 10 minutes in the future then the Rest API returns 401 not authorized. Well if the time of the users device is off by 10 minutes for some reason then the request will not work. Can someone confirm this? Any solution how to prevent this?
0
0
588
Jun ’23
Problem inserting weather metadata into workout.
I have two related functions to retrieve the weather and then insert it into a "Live Workout Builder"... The first function calls the second to get the weather info after which it inserts the metadata into the builder. public func stopGatheringLocationData() { logger.info("Stopped gathering location data...") Task { let (humidity, temperature) = await getCurrentWeather() if humidity != nil && temperature != nil { logger.log("Current humidity \(humidity!), temperature: \(temperature!)") let metaData = [HKMetadataKeyWeatherHumidity: humidity!, HKMetadataKeyWeatherTemperature: temperature!] logger.log("Current metadata: \(metaData)") do { try await workoutManager.liveBuilder?.addMetadata(metaData) } catch { logger.error("FAILED to add weather metadata to workout -> \(error.localizedDescription)") } } else { logger.error("FAILED to retrieve weather data...") } } locationManager.stopUpdatingLocation() } private func getCurrentWeather() async -> (humidity: HKQuantity?, temperature: HKQuantity?) { // Get the weather for the starting location... let tempUnit = HKUnit.degreeFahrenheit() let humidityUnit = HKUnit.percent() guard let startingLocation else { logger.error("No starting location...") return (nil, nil) } do { let wx = try await wxService.weather(for: startingLocation) let humidity = wx.currentWeather.humidity let temp = wx.currentWeather.temperature.converted(to: .fahrenheit) let curWx = wx.currentWeather let wxAttr = try await wxService.attribution.legalAttributionText await MainActor.run { currentWx = curWx wxServiceAttribution = wxAttr } return (HKQuantity(unit: humidityUnit, doubleValue: humidity), HKQuantity(unit: tempUnit, doubleValue: temp.value)) } catch { logger.error("FAILED to retrieve weather data -> \(error.localizedDescription)") return (nil, nil) } } The two log statements in the first function print out the following information: [Location/Weather] Current humidity 52 %, temperature: 76.226 degF [Location/Weather] Current metadata: ["HKWeatherTemperature": 76.226 degF, "HKWeatherHumidity": 52 %] However, when I look at the workout in the Activity app on my iPhone, the map generated by my app is present but the weather information is missing. The data looks formatted correctly per the limited documentation but for some reason that data is just not showing up. Any help greatly appreciated...
1
0
700
Jun ’23
Forecasted wind speed for different timestamps/durations
I am writing an integration with WeatherKit. I need to get several metrics of the Wind data like WindSpeed, windGust. In the CurrentWeatherData object I have all this data. However I also need to have the prediction of this metric slightly into the future. For example I need to get these levels in 5mins intervals from up to 30mins from now. NextHourForecastData seems like the obvious place for this considering it does show Forecasted data everyminute, however only for PrecipitationChance and PrecipitationIntensity. Is there a better dataSet that I can use? In fact I would already be happy to get the maximum during that period. It seems that the HourlyForecast would perhaps also be a solution but as far as I can tell this one is always linked to the start of the hour (i.e. XX:00) which makes it complicated to work with, and not very helpful if I'm making the request at XX:15, etc Alternatively I can get the currentWeather DataSet for multiple timestamps using the currentAsOf parameter. This is a crude approach but from what I can see to do that I would need to do multiple API calls which is rather wasteful and not exactly cheap for multiple systems/locations. Is there perhaps a way to make a call for multiple timestamps and/or locations? Many thanks in advance
0
0
509
Jun ’23
WeatherKit or SwiftUI date formatting issues
Hello! Hope you had an amazing Dub Dub week. I am currently integrating widgets into my weather app. The widgets use WeatherKit to get the hourly forecast. I have issues formatting or displaying dates for the locations. When I display the date for 2 or more locations with different timezones, the hours displayed are local for the phone, not the location I'm grabbing the weather for. This is how I display the date. hour is the Forecast item from WeatherKit. Text(hour.date.formatted(date: .omitted, time: .shortened)) Example: Neither of the locations' time is 9:00. They are in different time zones with 10 hours difference, one should be different from the other.
1
0
1.3k
Jun ’23
Widgets calling WeatherService.shared.weather multiple times at the same time
Hello. I noticed pretty early on that WeatherService.shared.weather seems to cache results. I realized this when I called it, killed network connectivity to my device, and then called it again I still got results back. My concern is about my widgets, which are also able to call WeatherService.shared.weather. I put my call inside of getTimeline(). After adding logging I realized that getTimeline() is called multiple times at the same time. For example, if I have two different widgets each with three different sizes (small, large, rectangular, etc) then six calls to getTimeline() are made for an update. I found a blog by Shopify iOS developers that describes how they found the same thing, but the forums aren't letting me link to their website's blog. My questions is which of these scenarios is happening: Even though WeatherService.shared.weather is called six times in the same second it's actually only the first call that goes out via the network and the remaining five calls just returned cached results. More than one of the six calls in the same second could be making a network call. If that's the case I'm going to need to add some form of throttling/caching because the number of free API calls per month is limited. Thank you!
1
0
884
Jun ’23
WeatherKit historical starting point
The web app that I work on has been using DarkSky for a few years and we have had historical weather data for many years prior to the date we integrated it. We rely on historical data for accurate reports and data analysis. The issue we are having now is it looks like WeatherKit only supports historical data back to 7/31/2021 which is almost 2 years but much less than DarkSky provided. Is that going to be the official start moving forward or will earlier data be supported eventually?
0
0
851
Jun ’23
MinuteWeather precipitationIntensity why speed not amount?
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
Replies
2
Boosts
0
Views
1.4k
Activity
Aug ’23
Hourly history with WeatherKit REST API
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.
Replies
11
Boosts
4
Views
6.2k
Activity
Aug ’23
WeatherKit REST API 401 Unauthorized {reason:NOT_ENABLED}
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
Replies
1
Boosts
1
Views
1.4k
Activity
Aug ’23
Project download for “meet weatherkit” WWDC2022-10003
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
Replies
1
Boosts
0
Views
779
Activity
Aug ’23
WeatherKit Location Precision
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?
Replies
0
Boosts
2
Views
817
Activity
Aug ’23
WeatherKit Swift / REST mismatch? daytimeForecast and overnightForecast not available via Swift?
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?
Replies
2
Boosts
0
Views
2.0k
Activity
Jul ’23
Use WeatherKit in an Xcode playground?
Can it be done? I can reliably crash Xcode by attempting the following in a playground: import UIKit import WeatherKit import CoreLocation let sanFrancisco = CLLocation(latitude: 37.7749, longitude: 122.4194) let weatherService = WeatherService() let weather = try await weatherService.weather(for: sanFrancisco) let temperature = weather.currentWeather.temperature print(temperature) Xcode 14.3.1 macOS 13.4.1
Replies
8
Boosts
1
Views
1.8k
Activity
Jul ’23
WeatherKit in a background operation?
Sorry if this is a stupid question but I haven't been able to find any information on whether an app can request and receive weatherKit data - the weather - while in the background. My app (AirCompare) makes extensive use of background URL sessions to fetch and process weather data. If certain conditions are met, a notification alert is sent to the user so the user can decide whether to activate the app. For instance if rain is in the forecast, the app alerts the user that they might want to close their windows. Making the app active will execute HomeKit control and accomplish that. Will I be able to replace the background URL session with the appropriate code and be able to fetch weather data in the background?
Replies
2
Boosts
0
Views
1.3k
Activity
Jul ’23
Cannot infer contextual base in reference to member 'fractionLength'
I am trying to format a measurement in my application as described in this documentation. Notice the example code: let temp = Measurement<UnitTemperature>(value: 38, unit: .celsius) let formattedTemp = temp.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1)))) // For locale: en_US: 100.4 degrees Fahrenheit When I try to do the same, I receive the following errors: Cannot infer contextual base in reference to member 'fractionLength' Cannot infer contextual base in reference to member 'numeric' Extra argument 'numberFormat' in call My code is as follows: Text("\(current.temperature.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1)))))") Where current is a CurrentWeather type provided by WeatherKit. Why is my adherence to the documentation causing these errors?
Replies
1
Boosts
0
Views
1.2k
Activity
Jul ’23
Weatherkit API always gives 500 error
https://weatherkit.apple.com/api/v1/weather/English/23.0685/72.6535 is the attempt that we are making. Is there anything wrong with the URL /
Replies
1
Boosts
0
Views
618
Activity
Jul ’23
Does Weatherkit have a webhook for push notifications?
I'm implementing PUSH NOTIFICATIONS for an app that uses Weatherkit ("there is a Tornado outside your house, run!") I enabled the capability, the code in app delegate, tested the push notification with the new apple console. and everything WORKS, BUT...how can I receive push notifications from Weather kit? do they have a webhook that I can listen to? I cannot find anything in the documentation. https://developer.apple.com/documentation/weatherkitrestapi/get_api_v1_weatheralert_language_id or do I need to create a server to call weatherkit every min? I don't understand how to listen to weather kit for alerts. thanks
Replies
1
Boosts
1
Views
904
Activity
Jun ’23
WeatherKit REST weather alerts
So, is the weatherAlerts field ever populated? From my (limited experience) it does not populate with current NWS alerts.
Replies
4
Boosts
0
Views
2.0k
Activity
Jun ’23
Weatherkit Rest API returns 401 if JWT timestamp is off by 10 minutes
I am using the Weatherkit Rest API successfully for Android. But I noticed that when I create a JSON Web Token with a timestamp for Issued at (iat) which is off by 10 minutes in the future then the Rest API returns 401 not authorized. Well if the time of the users device is off by 10 minutes for some reason then the request will not work. Can someone confirm this? Any solution how to prevent this?
Replies
0
Boosts
0
Views
588
Activity
Jun ’23
Problem inserting weather metadata into workout.
I have two related functions to retrieve the weather and then insert it into a "Live Workout Builder"... The first function calls the second to get the weather info after which it inserts the metadata into the builder. public func stopGatheringLocationData() { logger.info("Stopped gathering location data...") Task { let (humidity, temperature) = await getCurrentWeather() if humidity != nil && temperature != nil { logger.log("Current humidity \(humidity!), temperature: \(temperature!)") let metaData = [HKMetadataKeyWeatherHumidity: humidity!, HKMetadataKeyWeatherTemperature: temperature!] logger.log("Current metadata: \(metaData)") do { try await workoutManager.liveBuilder?.addMetadata(metaData) } catch { logger.error("FAILED to add weather metadata to workout -> \(error.localizedDescription)") } } else { logger.error("FAILED to retrieve weather data...") } } locationManager.stopUpdatingLocation() } private func getCurrentWeather() async -> (humidity: HKQuantity?, temperature: HKQuantity?) { // Get the weather for the starting location... let tempUnit = HKUnit.degreeFahrenheit() let humidityUnit = HKUnit.percent() guard let startingLocation else { logger.error("No starting location...") return (nil, nil) } do { let wx = try await wxService.weather(for: startingLocation) let humidity = wx.currentWeather.humidity let temp = wx.currentWeather.temperature.converted(to: .fahrenheit) let curWx = wx.currentWeather let wxAttr = try await wxService.attribution.legalAttributionText await MainActor.run { currentWx = curWx wxServiceAttribution = wxAttr } return (HKQuantity(unit: humidityUnit, doubleValue: humidity), HKQuantity(unit: tempUnit, doubleValue: temp.value)) } catch { logger.error("FAILED to retrieve weather data -> \(error.localizedDescription)") return (nil, nil) } } The two log statements in the first function print out the following information: [Location/Weather] Current humidity 52 %, temperature: 76.226 degF [Location/Weather] Current metadata: ["HKWeatherTemperature": 76.226 degF, "HKWeatherHumidity": 52 %] However, when I look at the workout in the Activity app on my iPhone, the map generated by my app is present but the weather information is missing. The data looks formatted correctly per the limited documentation but for some reason that data is just not showing up. Any help greatly appreciated...
Replies
1
Boosts
0
Views
700
Activity
Jun ’23
Forecasted wind speed for different timestamps/durations
I am writing an integration with WeatherKit. I need to get several metrics of the Wind data like WindSpeed, windGust. In the CurrentWeatherData object I have all this data. However I also need to have the prediction of this metric slightly into the future. For example I need to get these levels in 5mins intervals from up to 30mins from now. NextHourForecastData seems like the obvious place for this considering it does show Forecasted data everyminute, however only for PrecipitationChance and PrecipitationIntensity. Is there a better dataSet that I can use? In fact I would already be happy to get the maximum during that period. It seems that the HourlyForecast would perhaps also be a solution but as far as I can tell this one is always linked to the start of the hour (i.e. XX:00) which makes it complicated to work with, and not very helpful if I'm making the request at XX:15, etc Alternatively I can get the currentWeather DataSet for multiple timestamps using the currentAsOf parameter. This is a crude approach but from what I can see to do that I would need to do multiple API calls which is rather wasteful and not exactly cheap for multiple systems/locations. Is there perhaps a way to make a call for multiple timestamps and/or locations? Many thanks in advance
Replies
0
Boosts
0
Views
509
Activity
Jun ’23
WeatherKit or SwiftUI date formatting issues
Hello! Hope you had an amazing Dub Dub week. I am currently integrating widgets into my weather app. The widgets use WeatherKit to get the hourly forecast. I have issues formatting or displaying dates for the locations. When I display the date for 2 or more locations with different timezones, the hours displayed are local for the phone, not the location I'm grabbing the weather for. This is how I display the date. hour is the Forecast item from WeatherKit. Text(hour.date.formatted(date: .omitted, time: .shortened)) Example: Neither of the locations' time is 9:00. They are in different time zones with 10 hours difference, one should be different from the other.
Replies
1
Boosts
0
Views
1.3k
Activity
Jun ’23
Widgets calling WeatherService.shared.weather multiple times at the same time
Hello. I noticed pretty early on that WeatherService.shared.weather seems to cache results. I realized this when I called it, killed network connectivity to my device, and then called it again I still got results back. My concern is about my widgets, which are also able to call WeatherService.shared.weather. I put my call inside of getTimeline(). After adding logging I realized that getTimeline() is called multiple times at the same time. For example, if I have two different widgets each with three different sizes (small, large, rectangular, etc) then six calls to getTimeline() are made for an update. I found a blog by Shopify iOS developers that describes how they found the same thing, but the forums aren't letting me link to their website's blog. My questions is which of these scenarios is happening: Even though WeatherService.shared.weather is called six times in the same second it's actually only the first call that goes out via the network and the remaining five calls just returned cached results. More than one of the six calls in the same second could be making a network call. If that's the case I'm going to need to add some form of throttling/caching because the number of free API calls per month is limited. Thank you!
Replies
1
Boosts
0
Views
884
Activity
Jun ’23
WeatherKit not showing Temp Correctly on device
Hi, I'm in the process of developing a weather app using WeatherKit. Everything seems to be working fine in the Simulator, but when I put it on the device (iPhone 13 Pro Max) the temperature displays wrong. Example: On Simulator: 34 F On Device: 34.98 F Anyone else have this problem? Dan Uff
Replies
2
Boosts
0
Views
1.5k
Activity
Jun ’23
WeatherKit historical starting point
The web app that I work on has been using DarkSky for a few years and we have had historical weather data for many years prior to the date we integrated it. We rely on historical data for accurate reports and data analysis. The issue we are having now is it looks like WeatherKit only supports historical data back to 7/31/2021 which is almost 2 years but much less than DarkSky provided. Is that going to be the official start moving forward or will earlier data be supported eventually?
Replies
0
Boosts
0
Views
851
Activity
Jun ’23
WeatherKit: Data Quality & Accuracy
Is there a study or report for the WeatherKit accuracy that can be downloaded? Something similar to what's found on OpenWeather's site ( https://openweathermap.org/accuracy-and-quality ).
Replies
0
Boosts
1
Views
649
Activity
Jun ’23