无法为 macOS 的 com.apple.weatherkit.authservice 生成 jwt 令牌

Nat*_*han 6 macos swift swiftui weatherkit

我试图获取我所在位置当前的天气,但是我得到以下信息:

无法为 com.apple.weatherkit.authservice 生成 jwt 令牌,并出现错误:Error Domain=WeatherDaemon.WDSJWTAuthenticatorServiceListener.Errors Code=2“(null)”

    class LocationManager: NSObject, ObservableObject{

        @Published var currentLocation: CLLocation?
        private let locationManager = CLLocationManager()

        override init(){
            super.init()
            locationManager.desiredAccuracy = kCLLocationAccuracyBest
            locationManager.distanceFilter = kCLDistanceFilterNone
            locationManager.requestAlwaysAuthorization()
            locationManager.startUpdatingLocation()
            locationManager.delegate = self
    
    }
}
extension LocationManager: CLLocationManagerDelegate{
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    
        guard let location = locations.last, currentLocation == nil else {return}
    
        DispatchQueue.main.async {
            self.currentLocation = location
        }
    }
    func locationManager(_ manager: CLLocationManager,
                     didFailWithError error: Error) {
        print( "location manager failed with error \(error)" )
    }
}
Run Code Online (Sandbox Code Playgroud)
struct MainView: View {
    
    let weatherService = WeatherService.shared
    @StateObject private var locationManager = LocationManager()
    
    var body: some View {
        VStack{
            Text("Hello, World!")
        }.task(id: locationManager.currentLocation){
            do{
                if let location = locationManager.currentLocation{
                    let weather = try await weatherService.weather(for: location)
                    print(weather)
                }
            }catch{
                print(error)
            }
        }
        
    }
}
Run Code Online (Sandbox Code Playgroud)

我已将天气套件功能添加到我的应用程序信息和开发人员门户上,有何作用?

Nat*_*han 16

您还需要在开发人员仪表板上Apps services的选项卡上启用它Edit your App ID Configuration- 它并不明显,也没有概述。

在此输入图像描述