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"
);
} }))