swiftwwdcweatherkit

WeatherKit⛈ iOS SDK 401 network error WWDC 2022


I am getting an error while running WWDC22 Link

I downloaded the sample Project from Apple from here

And I am able to run the project. But when I create a Demo project and added Weather fetching code getting I am getting Error.

My Code:

func fetchWeather() async {
       let service = WeatherService.shared
        var location: CLLocation = CLLocation(latitude: 22.7196, longitude: 75.8577)
        
        let weatherData = try? await service.weather(for: location, including: .current)
        print(weatherData)
    }

Error:

2022-06-22 17:31:48.470130+0530 WeatherAPIDemo[25490:231389] [Database] Attempting to invalidate an assertion that is no longer valid 2022-06-22 17:31:49.208346+0530 WeatherAPIDemo[25490:231387] [WeatherService] Encountered an error when fetching weather data subset; location= +/- 0.00m (speed -1.00 mps / course -1.00) @ 6/22/22, 5:31:48 PM India Standard Time,  error=invalidJWTResponse(Optional( { URL: https://weather-data.apple.com/v2/token } { Status Code: 401, Headers {
    Connection =     (
        close
    );
    "Content-Length" =     (
        0
    );
    Date =     (
        "Wed, 22 Jun 2022 12:01:49 GMT"
    );
    Server =     (
        Apple
    );
    "Strict-Transport-Security" =     (
        "max-age=31536000; includeSubdomains"
    );
    "X-Apple-Origin" =     (
        "8961098f-b238-3714-ba44-5b569c861456"
    );
    "X-Cache" =     (
        "TCP_MISS from a49-44-192-207.deploy.akamaitechnologies.com (AkamaiGHost/10.8.2-41841244) (-)"
    );
    "X-Content-Type-Options" =     (
        nosniff
    );
    "X-Frame-Options" =     (
        SAMEORIGIN
    );
    "X-REQUEST-ID" =     (
        "8c733cde-5aa3-499c-b555-05c5aab5e278"
    );
    "X-XSS-Protection" =     (
        "1; mode=block"
    );
} }))
nil

Solution

  • I tried a lot even I have added WeatherKit in Capabilities But didn't worked.

    I thought the issue must be that I don’t have the Developer Account But then I realised that the Apple Demo Project is also working even without adding any Team (see below img for Apple Demo Project).

    enter image description here

    Then I just copy and pasted the same Bundle Identifier in my Demo project and Boom! it worked like Hell.