gpt4 book ai didi

ios - 找不到 WeatherKit 历史数据和归因问题

转载 作者:行者123 更新时间:2023-12-05 04:28:30 33 4
gpt4 key购买 nike

我想将一些历史天气数据添加到应用程序中。我可以使用新的WeatherKit 获取当前天气但找不到任何信息来告诉我如何访问历史数据。 WWDC 视频之一提到了添加开始和结束WeatherService 电话的日期,但我找不到这方面的任何信息。

此外,我还在努力满足归因要求。我可以让它工作,但只能在灯光模式。当设备处于深色模式时,Apple Weather Logo 只是一个白色的深色背景中的框(我假设 Logo 在那里,但为白色 - 但无法证明这一点)。

enter image description here

enter image description here

这是一个简化版本 - 仅获取当前天气:

struct ContentView: View {

@Environment(\.colorScheme) var colorScheme

@State private var weather: Weather?
@State private var attLogo: URL?
@State private var attributionURL: URL?
@State private var logoImage: Image?

let weatherService = WeatherService.shared

var body: some View {
VStack {
if let weather {
VStack {
Text("San Francisco")
.font(.largeTitle)
Text("\(weather.currentWeather.temperature.formatted()) | \(weather.currentWeather.condition.description)")
}
}//if let
Spacer()

//white letters on white box if device in dark mode
AsyncImage(url: attLogo)

Group{
if let attributionURL {
Link("Weather Attribution", destination: attributionURL)
}
}//att group
}//outer v
.padding()
.task {
do {
let location = CLLocation(latitude: 37.77, longitude: -122.41)
self.weather = try await weatherService.weather(for: location)
} catch {
print(error)
}//do catch
}//task 1
.task {
do {
let attribution = try await weatherService.attribution
let attributionLink = attribution.legalPageURL
self.attributionURL = attributionLink
let attributionLogo = colorScheme == .light ? attribution.combinedMarkDarkURL : attribution.combinedMarkLightURL
self.attLogo = attributionLogo
} catch {
print("failed to load attribution")
}
}//task for logo and link
}//body
}//struct

任何指导将不胜感激。模拟器中的 Xcode 14.0 Beta、iOS 16.0 (20A5283p)

最佳答案

自 7 月 10 日起,提供的链接上的两个 Logo 均不可用。我现在在 AsyncImage 中创建了一个 placeholder,我不知道它是否会通过 Apple 的检查,但对于 Beta/离线解决方案来说似乎是可行的。

if let arributionLogo = arributionLogo{
AsyncImage(url: arributionLogo) { image in
image.scaledToFit()
} placeholder: {
Label("Apple Weather", systemImage: "cloud.sun.fill")
}
}else{
ProgressView()
}
if let arributionLink = arributionLink{
Link("Other data sources", destination: arributionLink)
}else{
ProgressView()
}

历史天气现在可用

let forecast = try await weatherService.weather(for: location, including:.hourly(startDate: startDate, endDate: endDate))

let forecast = try await weatherService.weather(for: location, including: .daily(startDate: startDate, endDate: endDate))

关于ios - 找不到 WeatherKit 历史数据和归因问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72581627/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com