WeatherKit iOS SDK 401 network error

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"

    );

} }))
Answered by Jevon_Mao in 716188022

Originally I thought the issue was I didn't wait long enough for App ID to register, but its been a while, and the error still persists.

Accepted Answer

Originally I thought the issue was I didn't wait long enough for App ID to register, but its been a while, and the error still persists.

Did you enable WeatherKit in the apps Signing & Capabilities section for the app?

You have to enable the Capabilities & App Services for your App ID in developer portal then wait for 30 minutes to get your app activated in Apple servers. Till then you will get 401 error.

Detailed steps given in the blog post

https://betterprogramming.pub/wwdc22-get-started-with-weatherkit-202794853c01

Thank you Rob Sturgeon

I have the same issues. I followed the setup instructions step by step. I enabled WeatherKit at capabilities in Xcode, and enabled WeatherKit in my dev.account. It was three hours ago, but I still have the 401 network error.

The same issue.

I'm also getting a 401 response code. I've tried running the demo code on Mac, iPhone (simulator running iOS 16), and iPad (physical device running iPadOS 16). My App ID configuration in the developer portal has WeatherKit checked in both "Capabilities" and "App Services". My Xcode project has WeatherKit added as a capability in "Signing & Capabilities". I've waited an hour since setting up my App ID in the developer portal. I'm not sure what else there is to try at this point...

I am having the same problem unfortunately.

Same here. Followed the README steps for the FlightPlanner app sample code, waited a few hours, tested, failed with invalidJWTResponse error. That was 8 hours ago, still getting the same error.

I guess the "good" news is that a comment in the source code explained the workaround for other broken sample code Apple has on their site :/

I'm having the exact same issue. I following the setup steps (checked both boxes on the developer website), added the WeatherKit capability to the app. It's been about 2 hours and still getting the 401.

I'm also having the same issue...

Same here on macOS. My App ID configuration in the developer portal has WeatherKit checked in both "Capabilities" and "App Services". My Xcode project has WeatherKit added as a capability in "Signing & Capabilities".

+1 from me too, have configured everything as described and receiving the 401.

Given that this feature has to be tied to your developer account in some way to count the number of requests you make, and given a 401 error, I would guess that something hasn't been wired up yet to send the right credentials to the API for developer accounts.

Same issue, For people who have weather kit working, in the dev portal under the Services tab: WeatherKit: Manage your weather kit usage I see a Coming soon greyed out box, ,is that the same for you?

Same here

Working for me now!

Just started working for me today!

Same problem here.

I see that a couple of you have said it resolved. What (if anything) did you do? Or is it just that the App ID provisioning is taking a long long time. ???

Finally got mine working.

I think what got me going was realizing that, on the dev website, where you create the App ID. You have to select WeatherKit in BOTH Capabilities AND App Services.

Once I had both of those checked, it still took another 30 mins or so for it to take effect.

Great advise! When setting the identifier, I had also only clicked on Weather Kit in one place. After clicking it it in two places, 30 minutes later it was working for me.

Just in case anyone else makes the same mistake I did. When adding the Bundle Identifier under Signing & Capabilities, somehow I had added it to the iOS section, but not to the field directly under Team (maybe because I added the BundleID before changing the Team to me?). I noticed this after reading through this post and going back to check if I had everything correct. I saw that there were 2 Bundle Identifier fields and the top one still had the Apple sample project BundleID. When I copied my BundleID to the field underneath Team, everything started working (& the 2nd Bundle Identifier field in the iOS section just disappeared).

Interesting. I get a bunch of errors none of them are a 401 error

2022-06-11 22:24:35.338896+0100 PlayWithWeatherKit[15269:254812] [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=0x600000bcf9f0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

and

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.

and

[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"))

and

[] nehelper sent invalid response: <dictionary: 0x1ffa87480> { count = 1, transaction: 0, voucher = 0x0, contents =
	"XPCErrorDescription" => <string: 0x1ffa87618> { length = 18, contents = "Connection invalid" }
}

and well here are the rest of the errors

2022-06-11 22:24:35.411005+0100 PlayWithWeatherKit[15269:254811] [] nw_parameters_set_source_application_by_bundle_id_internal Failed to convert from bundle ID (net.tarasis.test.wwdc) to UUID. This could lead to wrong data usage accounting.

2022-06-11 22:24:35.411569+0100 PlayWithWeatherKit[15269:254811] [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" [M]

2022-06-11 22:24:35.411786+0100 PlayWithWeatherKit[15269:254811] [] nw_resolver_can_use_dns_xpc_block_invoke Sandbox does not allow access to com.apple.dnssd.service

2022-06-11 22:24:35.412005+0100 PlayWithWeatherKit[15269:254811] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:14 Err:-1 Errno:1 Operation not permitted

2022-06-11 22:24:35.412030+0100 PlayWithWeatherKit[15269:254811] [connection] nw_resolver_create_dns_service_locked [C1.1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)

2022-06-11 22:24:35.412278+0100 PlayWithWeatherKit[15269:254811] Connection 1: received failure notification

2022-06-11 22:24:35.413027+0100 PlayWithWeatherKit[15269:254811] Connection 1: failed to connect 10:-72000, reason -1

2022-06-11 22:24:35.413043+0100 PlayWithWeatherKit[15269:254811] Connection 1: encountered error(10:-72000)

2022-06-11 22:24:35.427967+0100 PlayWithWeatherKit[15269:254819] Task <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<1> HTTP load failed, 0/0 bytes (error code: -1003 [10:-72000])

2022-06-11 22:24:35.429292+0100 PlayWithWeatherKit[15269:254819] Task <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<1> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x600000bf4bd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns, _kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<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}

2022-06-11 22:24:35.429749+0100 PlayWithWeatherKit[15269:254819] [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:24:35 British Summer Time,  error=Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x600000bf4bd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns, _kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<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/ContentView.swift:28: Fatal error: Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x600000bf4bd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns, _kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<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}

2022-06-11 22:24:35.429869+0100 PlayWithWeatherKit[15269:254810] PlayWithWeatherKit/ContentView.swift:28: Fatal error: Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x600000bf4bd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, ipv6, dns, _kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(

    "LocalDataTask <97DDE838-005D-4CE0-BD5A-59DB58969B42>.<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}

Baffled why this is happening. Esp as I can go to the url in safari.

The directory is

drwxr-xr-x tarasis staff 544 B  Mon Jun  6 23:10:55 2022  Weather

Is that the name of a place in china? The city near where I live in New York, USA is named Syracuse.

Same for me, and on the web I am not allowed to do something ion regard to WeatherKit.

Does it work on a proper beta device (NOT the simulator)?

When configuring the app id on the developer site there are two tabs: "Capabilities" and "App Services". Ensure that WeatherKit is enabled in both of these.

Have been having the same issue for 3 days now. WeatherKit is enabled in both Capabilities and App Services as well as being added as a capability in Xcode. Even created a new provisioning profile and no dice. Very frustrating...

WeatherKit iOS SDK 401 network error
 
 
Q