我正在尝试使用WeatherKit来获取一个位置的简单天气预报。
do {
let location = CLLocation(latitude: 37.3346, longitude: -122.0087)
let weather = try await WeatherService().weather(for: location)
} catch {
print(error)
}
当我在物理设备上运行它时,我在控制台中得到一个空的Weather对象和以下内容:
[WeatherDataService] Response did not contain requested dataset: .appLocationConfig. Returning default value: AppLocationConfig(reportAnIssue: ReportIssueLocationConfig(position: beforeFooter, minDaysSinceInteraction: 0), expireTime: 2022-11-27 04:31:20 +0000
Xcode正在管理我的配置文件,我已经添加了WeatherKit功能,我有一个活跃的苹果开发者计划会员,所以我不认为我应该有任何问题访问WeatherKit。发生了什么事,我该怎么解决?
无论您是否认为这是对问题的修复,将including
参数添加到调用中为我解决了问题。
所以不用
let weather = try await WeatherService().weather(for: location)
你可以调用
let weather = try await WeatherService().weather(for: location, including: .current)
它应该返回与原始调用相同的信息。