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

76 Posts
Sort by:
Post marked as solved
1 Replies
119 Views
I have a Swift app that fetches current conditions and daily forecasts. It is in production and working without issues. My question is whether the fetch I am using counts as a single “request” for usage thresholds, or two (one for current conditions, one for daily forecast)? I need current conditions more often than daily forecast, so if this is counting as two requests, I could refactor the logic to get each separately as needed. But separating the requests would use more quota if the combined fetch counts as a single request. let service = WeatherService() let location = CLLocation(latitude: weatherData.lat, longitude: weatherData.lon) let startOfToday = Calendar.current.startOfDay(for: Date()) let endDate = Calendar.current.date(byAdding: DateComponents(day: 2), to: startOfToday)! let current: CurrentWeather let daily: Forecast<DayWeather> (current, daily) = try await service.weather(for: location, including: .current, .daily(startDate: startOfToday, endDate: endDate))
Posted
by
3no
Post not yet marked as solved
1 Replies
127 Views
This is one of the comments to my weather app from users and also most of users think like that: Ever since Apple bought Dark Sky it's been wildly inaccurate. How does it possible? What you think?
Posted
by
mcy
Post not yet marked as solved
0 Replies
172 Views
Has anyone else been experiencing issues with the WeatherKit API recently? Since Saturday we've been seeing about 1.5% of our requests time out. Apple hasn't posted anything on their status page https://developer.apple.com/system-status/ and the issue doesn't seem to be getting any better.
Posted
by
Post marked as solved
1 Replies
185 Views
We have been using the Weather Kit without any issues for the past year and a half. However, recently we have encountered a recurring problem with the WeatherKIT API. It has been responding with {"reason": "NOT_ENABLED"} for every request made. Last Saturday, I created a new Service ID, and it resolved the issue temporarily. However, today it started responding with {"reason": "NOT_ENABLED"} again. What steps should I take to resolve this issue?
Posted
by
Post not yet marked as solved
1 Replies
224 Views
My MacBook Air M2 system version macOS Sonoma 14.5 Beta (23F5049f) The error occurred: from the end of March 2024 to today (April 8, 24) Problem: The system positioning information is seriously wrong, including but not limited to: time zone, Safari, map app, weather app, search app... (PS. The positioning is correct when using Google Chrome and Google Maps, but it is still wrong when using Google Maps on Safari) Background: I came to Germany from mainland China at the end of March. The Apple ID region I use is Germany. The location of my iPhone and Apple Watch can be refreshed to Germany normally, and several of my AirTags have been refreshed to Germany. Tried but failed: I searched for some bash commands to try to clear and clear the cache of the map app and system location information. rm -rf ~/Library/Containers/com.apple.Maps rm -rf ~/Library/Application\ Support/com.apple.findmy sudo rm -rf /Library/Caches/com.apple.GeoServices sudo rm -rf /Library/Caches/com.apple.locationd defaults delete com.apple.locationd.plist Turn off location services in System Settings > Privacy and Security, shut down and restart the phone, and then turn the service back on. Turn my VPN on and off. Clear my network information. Since there are many files saved, the restore operation is not planned. 我的MacBook Air M2 系统版本macOS Sonoma 14.5 Beta版(23F5049f) 错误发生时间:2024年3月底到今天(24年4月8日) 问题:系统定位信息严重错误,包括但不限于:时区、Safari、地图app、天气app、查找app... (PS.使用Google Chrome浏览器与Google Maps时定位正确,Safari使用Google Maps仍然错误) 背景: 我从3月底从中国大陆来到欧洲德国。 我使用的Apple ID地区是德国的。 我的iPhone和Apple Watch定位能正常刷新到德国,且我几个AirTag已经刷新到德国。 尝试但都未成功: 我搜索了一些bash命令尝试清除、清空地图app和系统位置信息的缓存。 rm -rf ~/Library/Containers/com.apple.Maps rm -rf ~/Library/Application\ Support/com.apple.findmy sudo rm -rf /Library/Caches/com.apple.GeoServices sudo rm -rf /Library/Caches/com.apple.locationd defaults delete com.apple.locationd.plist 关闭系统设置>隐私与安全中的定位服务,关机重启,再重开这项服务。 开关我的VPN。 清除我的网路信息。 由于保存的文件较多,不打算进行还原操作。
Posted
by
Post not yet marked as solved
0 Replies
236 Views
Trying to get weather data for a specific location and specific timezone. Generated Service identifier and Private Key, from Apple developer site. Then Generated public key Generated jwt token from jwt.io by keying in the payload, header, public, and private key. Header { "alg" : "ES256", // predefined "kid" : “keyid” , // key id created for WeatherKit "id" : “developer_team_account_id.com.company_name.MyWeatherKit, "typ" : "JWT" } Payload { "iat" : 1710117942, "exp" : 1710204342, "iss" : "developer_team_account_id", "sub" : "com.company_name.MyWeatherKit } I Then call this function: func getWeatherData(requestId: String, latitudeStr: String, longitudeStr: String, completion: @escaping (Bool) -> () ){ var country = "US" var language = "en" var tz = "CST" let jwtToken = "token here...." let urlString:String = "https://weatherkit.apple.com/api/v1/availability/" + language + "/" + latitudeStr + "/" + longitudeStr + "?" + "country=" + country + "&" + "timezone=" + tz print("Apple weather urlString: \(urlString)") let weatherURL = URL(string: urlString) var request = URLRequest(url: weatherURL!) request.httpMethod = "GET" request.setValue("Bearer \(jwtToken)", forHTTPHeaderField: "Authorization") let dataTask = URLSession.shared.dataTask(with:weatherURL!) { [self] responseData, response, error in do { print(response as Any) print(error as Any) if let data = responseData { try DispatchQueue.main.sync { [unowned self] in let decoder = JSONDecoder() let jsonData = try decoder.decode(Top.self, from: data) // parse data here print(jsonData) completion(true) } } } catch { print("error: \(error.localizedDescription)") completion(false) } } dataTask.resume() } Gives response with code 403 Optional(<NSHTTPURLResponse: 0x280cbcf00> { URL: https://weatherkit.apple.com/api/v1/availability/en/29.928894042968750/-95.607747517125430?country=US&timezone=CST } { Status Code: 403, Headers { "Access-Control-Allow-Origin" = ( "*" ); Connection = ( close ); "Content-Security-Policy" = ( "default-src 'self';" ); Date = ( "Tue, 12 Mar 2024 02:52:18 GMT" ); Server = ( Apple ); "Strict-Transport-Security" = ( "max-age=31536000; includeSubdomains" ); "X-Cache" = ( "TCP_MISS from a23-38-189-78.deploy.akamaitechnologies.com (AkamaiGHost/11.4.3-54729273) (-)" ); "X-Content-Type-Options" = ( nosniff ); "X-Frame-Options" = ( SAMEORIGIN ); "X-REQUEST-ID" = ( "bac7e5dc-c5fd-6f85-263b-8f59b169cd2f" ); "X-XSS-Protection" = ( "1; mode=block" ); } }) The URL I am passing is : https://weatherkit.apple.com/api/v1/availability/en/29.928894042968750/-95.607747517125430?country=US&timezone=CST Am I calling the wrong URL? Or is Apple weather service down? I am at a loss to understand. I need some help and guidance
Posted
by
Post not yet marked as solved
1 Replies
376 Views
Hello, Our team is leveraging WeatherKit for our product, with requirements to obtain historical, current, and forecasted weather data. Our research indicates that WeatherKit supports all these needs, albeit with a caveat regarding historical data. According to this discussion on the developer forums, historical data should be available post-August 2021. However, we've encountered issues accessing historical data for certain locations beyond this date. Are these gaps in data availability a known issue within WeatherKit's service? If so, could you provide any insights into when we might expect a resolution? Thank you for your assistance.
Posted
by
Post marked as solved
4 Replies
563 Views
We have an app that allows users to fetch historical weather data for their selected locations. We are seeing users report failures for specific latitudes and longitudes that come back as WeatherDaemon.WDSClient<WeatherDaemon.WeatherResource>.Errors.responseFailed For example, this request always fails: https://weather-data.apple.com/v3/weather/en-US/33.797/-111.775?timezone=America/Phoenix&dataSets=forecastDaily&dailyStart=2023-12-29T07:00:00Z&dailyEnd=2023-12-31T07:00:00Z&country=US&deviceLanguages=en-US&clientMetadata=<REDACTED> Another example for another location: https://weather-data.apple.com/v3/weather/en-AU/40.717/-74.000?timezone=America/New_York&dataSets=forecastDaily&dailyStart=2023-12-29T05:00:00Z&dailyEnd=2023-12-30T05:00:00Z&country=US&deviceLanguages=en-AU,es-AU&clientMetadata=<REDACTED> Both example involve queries at the end of December 2023. I have filed this as FB13608710 with example code that replicates this as it is being used in our app.
Posted
by
Post not yet marked as solved
1 Replies
307 Views
I've tried to find the solution to my issue on this forum and general web searches. I see a lot of similar issues but no clear advice how to answer. I have some fairly simple code to get a .daily historical weather object as below: var gameLocation: CLLocation = CLLocation() switch game.country { case .us: gameLocation = CLLocation(latitude: homeTeam.sFactors.gpsCoord.lat, longitude: homeTeam.sFactors.gpsCoord.long) case .germany: gameLocation = CLLocation(latitude: GameCountry.germany.gpsCoord.lat, longitude: GameCountry.germany.gpsCoord.long) case .uk: gameLocation = CLLocation(latitude: GameCountry.uk.gpsCoord.lat, longitude: GameCountry.uk.gpsCoord.long) case .mexico: gameLocation = CLLocation(latitude: GameCountry.mexico.gpsCoord.lat, longitude: GameCountry.mexico.gpsCoord.long) } var gameStartDate: Date = Date() do { gameStartDate = try DateRelatedHelpers().convertISO8601StringToDate(from: game.date) print("Date string: \(game.date), Date: \(gameStartDate)") } catch { throw DateHelperError.invalidDateString } let gameEndDate = Calendar.current.date(byAdding: .day, value: 1, to: gameStartDate)! let gameWeather = try! await weatherService.weather(for: gameLocation, including: .daily(startDate: gameStartDate, endDate: gameEndDate)) I call the function from a loop which is going through several different locations to fetch. I get some valid responses then I receive the following error: Received invalid http response code 404 for request: C2A50990-2E03-497B-BC48-EF7560524E00 Encountered an error when fetching weather data subset; location=<+39.27745100,-76.62297400> +/- 0.00m (speed -1.00 mps / course -1.00) @ 1/24/24, 8:32:28 PM Central Standard Time, error=responseFailed: 404 WeatherDaemon.WDSClient<WeatherDaemon.WeatherResource>.Errors.responseFailed(<NSHTTPURLResponse: 0x6000003d5dc0> { URL: https://weather-data.apple.com/v3/weather/en-US/39.277/-76.623?timezone=America/New_York&dataSets=forecastDaily&dailyStart=2023-09-10T17:00:00Z&dailyEnd=2023-09-11T17:00:00Z&country=US&deviceLanguages=en-US&clientMetadata=CgJVUxoFZW4tVVNKAFABWBRgA4ABA5gBALoBAhAB4gEICgseHR8hICLyAQJVUw } { 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, 25 Jan 2024 02:32:29 GMT" ); Expires = ( "Thu, 25 Jan 2024 02:32:29 GMT" ); Pragma = ( "no-cache" ); Server = ( Apple ); "Strict-Transport-Security" = ( "max-age=31536000; includeSubdomains" ); "X-Apple-Origin" = ( "f6fe362e-be7c-35f4-b131-3b1f903b4bca" ); "X-Cache" = ( "TCP_MISS from a184-28-40-133.deploy.akamaitechnologies.com (AkamaiGHost/11.4.0-53477943) (-)" ); "X-Content-Type-Options" = ( nosniff ); "X-Frame-Options" = ( SAMEORIGIN ); "X-REQUEST-ID" = ( "C2A50990-2E03-497B-BC48-EF7560524E00" ); "X-XSS-Protection" = ( "1; mode=block" ); } }, Optional("")) I also get this warning on any call that receives data: Aborting silent interpolation: additional missing products that need to be fetched from the server anyway; location=CLLocationCoordinate2D(latitude: 39.277451, longitude: -76.622974), missing products=[WeatherDaemon.WeatherProduct.forecastDaily] My dates are in UTC time. I assume the calls return data in the local time of the location. Could this be an issue with Dates (i.e. local vs location date)? Any assistance would be appreciated.
Posted
by
Post not yet marked as solved
1 Replies
435 Views
I asked a similar question a while back: https://developer.apple.com/forums/thread/730946 Since then I have a new Mac and new iPhone and so I now have the hardware to actually play with WeatherKit. I've worked my way past all the entitlements stuff and have been able to use and expand on online examples. Cool. Trouble is, nearly every example you can find uses code designed to update the UI as fresh weather data is fetched. My app currently uses background URL fetches to obtain weather data, make some calculations and take appropriate actions, all in the background. Updating the UI was a separate challenge. So which asynchronous tool is the right one for this? How can I quickly update my existing code to call WeatherKit instead of going to a weather site for a download? I currently use something like a download task session: let weatherTask = session.downloadTask (with: URL(string: urlString)!) weatherTask.taskDescription = "weather" weatherTask.resume() or a dataTask session: var request = URLRequest(url: url) request.httpMethod = "GET" request.addValue("text/html", forHTTPHeaderField: "Content-Type") let taskWeatherPOP = URLSession.shared.dataTask(with: request) { (data, response, error) in if error != nil { print("Error is \(String(describing: error))") } if let POPData = data, let report = String(data: POPData, encoding: String.Encoding.utf8) { if weatherReportPOP.contains("ServiceUnavailable") { print("A Weather POP report error") } else { weatherReportPOP = report } // Close the IF service unavailable } // Closes the IF weather data is not nil } // Close Task Weather taskWeatherPOP.resume()
Posted
by
Post not yet marked as solved
0 Replies
310 Views
Hi! My app, Temp Blanket, uses WeatherKit to provide users with historical high and low temperatures (as well as some weather condition info) for the location from which they wish to request data - they enter the location in a textfield that I then convert to Geo Coordinates before passing on to WeatherKit. A user in Germany has informed me that her results for Dresden do not match the actual temperatures in the last few days. Actual temperates have been in the -13 to 2 C range and she is seeing a range of 4 to 21 C. In fact, she reports that she gets the same temperatures, no matter what location she tries. When I try Dresden in my app (from my office in Fort Lauderdale, FL) I get correct temperatures for Dresden. Another data point - If I try to get temperatures for Nairobi, Kenya for the last few days, I get the correct temperatures for yesterday (High of 22C, Low of 16C) but the prior days' temps are very far off. I get temps in the range of -12 to 1 C but the actual temps were 15 to 26 C. The temperature history data seems to work correctly in the UK, based on feedback from a user there. So, I have to wonder and ask - does WeatherKit historical data work correctly for all locations worldwide or is it not reliable in certain locations/countries? This is critical information to have so that we do not have dissatisfied users in countries where this service is not yet working correctly. I would disable the app in those countries if this were the case but I need to know what those countries are. Thanks in advance.
Posted
by
Post not yet marked as solved
1 Replies
369 Views
I'm getting my feet wet with weatherKit and have managed to get all the current weather I need with the code below. My app requires one more thing - the chance of precipitation in the next 0-20 minutes or so - in order to close the windows if the odds exceed some threshold. I haven't been able to find a single code example of retrieving the forecasted rain odds. It looks like the number I need will be in the MinuteWeather contained? in the HourlyForecast but it's completely a mystery to me how to extract what I need. I need a trail of breadcrumbs! I tried getting the hourly and daily forecasts but the value I'm looking for isn't there. import Foundation import WeatherKit @Observable class WeatherManager { private let weatherService = WeatherService() var weather: Weather? func getWeather(lat: Double, long: Double) async { do { weather = try await Task.detached(priority: .userInitiated) { [weak self] in return try await self?.weatherService.weather(for: .init(latitude: lat, longitude: long)) }.value } catch { print("Failed to get weather data. \(error)") } print("\(weather)") do { let daily = try await weatherService.weather(for: .init(latitude: lat, longitude: long), including: .daily) let hourly = try await weatherService.weather(for: .init(latitude: lat, longitude: long), including: .hourly) print("Daily: \(daily)") print("Hourly: \(hourly)") } catch let error { print("Failed to get the forecast. \(error)") } } // close getWeather function var icon: String { guard let iconName = weather?.currentWeather.symbolName else { return "--" } return iconName } var temperature: String { guard let temp = weather?.currentWeather.temperature else { return "--" } let convert = temp.converted(to: .fahrenheit).value return String(Int(convert)) + "°F" } var humidity: String { guard let humidity = weather?.currentWeather.humidity else { return "--" } let computedHumidity = humidity * 100 return String(Int(computedHumidity)) + "%" } var pressure: String { guard let press = weather?.currentWeather.pressure else { return "--" } let convertP = press.converted(to: UnitPressure.inchesOfMercury).value return String((convertP)) + " in. Hg" } var UVindex: String { guard let uv = weather?.currentWeather.uvIndex.value else { return "--" } return "\(uv)" + " index" } var POP: String { ???? return String(Int(chance)) + "%" } }
Posted
by
Post not yet marked as solved
0 Replies
328 Views
Hi, I am having an issue where I keep getting 404 errors for a particular Lat/Long date combination when trying to fetch historical hourly forecasts. It does not seem to matter if I supply an hourlyEnd value or not. I am always getting a 404 response. Here is the sample query I am passing to the weatherkit: https://weatherkit.apple.com/api/v1/weather/en/46.26013/-119.9061?dataSets=forecastHourly&timezone=PST&hourlyStart=2023-08-16T07:00:00Z&hourlyEnd=2023-08-16T15:00:00Z It seems for some reason nothing is showing up until the end of September when I was doing some tests and changing the dates and times. Is there a limit on how far back the historical can go? Any help would be appreciated! Thank you!
Posted
by
Post not yet marked as solved
0 Replies
276 Views
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?
Posted
by
Post not yet marked as solved
9 Replies
661 Views
We grid our service area with 6000 points across the US. There is 1 point in Missouri that fails forecast and anything historical (currentWeather, forecastHourly, and forecastDaily) with a 404 error: latitude = 37.06089340391355 longitude = -93.00383141966712 This works: latitude = 37.06089340391355 longitude = -93.006 This does NOT work: latitude = 37.06089340391355 longitude = -93.005 Even though all of the other points seem to be working, I have lack in trust for this API for returning unexpected results. Can someone please provide an explanation or resolution?
Posted
by
Post not yet marked as solved
1 Replies
307 Views
I am looking at the forecastHourly data for the same latitude and longitude, from 3 days ago at 00:00 to today at 00:00. I noticed that every hour, around the 15th minute, the reportedTime in the forecastHourly metadata changes: "readTime": "2023-12-20T07:15:45Z", -> 2023-12-20T07:21:45Z "reportedTime": "2023-12-20T06:00:00Z", -> 2023-12-20T07:01:18Z The data for the same time in the past (where the value of forecastStart is the same) is different. What is the reason for this? "readTime": "2023-12-20T07:15:45Z", -> 2023-12-20T07:21:45Z "reportedTime": "2023-12-20T06:00:00Z", -> 2023-12-20T07:01:18Z "forecastStart": "2023-12-18T15:00:00Z", === 2023-12-18T15:00:00Z "humidity": 0.47, -> 0.46 "temperature": -6.38 -> -6.72
Posted
by
Post not yet marked as solved
0 Replies
301 Views
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
Posted
by
Post not yet marked as solved
9 Replies
980 Views
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?
Posted
by