尝试让 WeatherKit Beta 正常工作。使用苹果提供的 WWDC 示例或加载天气数据的简单项目,在模拟器和物理设备上的 Xcode 14 Betas 3/4/5 上都出现了相同的错误。
错误输出始终是:
2022-08-12 15:56:02.825925-0400 WeatherPup[47533:15014528] [AuthService] 无法为 com.apple.weatherkit.authservice 生成 jwt 令牌,错误:Error Domain=AMSErrorDomain Code=12“Mescal Failed”UserInfo ={NSLocalizedDescription=Mescal 失败,NSLocalizedFailureReason=SAPInit 失败:-42049}
有人已经成功使用这个 Beta 进行构建了吗?我想它应该可以工作,因为黑暗天空天气服务仍在运行。
我拥有应有的所有证书、标识符和权限设置,以及经过三重检查的捆绑包标识符等。
我试图获取我所在位置当前的天气,但是我得到以下信息:
无法为 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) TimelineProvider我正在尝试为 iOS 16制作一个WeatherKit,但我正在努力解决如何满足协议签名并使用新的异步 api 的问题。
这是我的代码:
struct WeatherProvider: TimelineProvider {
func getSnapshot(in context: Context, completion: @escaping (WeatherEntry) -> ()) {
let weather = try? await WeatherService.shared.weather(for: currentLocation)
let entry = WeatherEntry(date: Date(), wind: nil, locationAuthStatus: nil)
completion(entry)
}
// etc
}
Run Code Online (Sandbox Code Playgroud)
编译此命令会引发构建错误'async' call in a function that does not support concurrency。
自动修复建议:Add 'async' to function 'getSnapshot(in:completion:)' to make it asynchronous
但如果你这样做,结构就不再符合:Type 'WeatherProvider' does not conform to protocol 'TimelineProvider'
这感觉应该是微不足道的,但我找不到任何关于如何做到这一点的例子。