WeatherKit error in displaying attribution information

46 Views Asked by At

I have the weatherKit Service working. I need to display Apple logo. Edited code as suggested

struct WView: View {

@Environment(\.colorScheme) var colorScheme

@State private var weather: Weather?
@State private var attributionLogo: 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()
        Group {
            if let logo = self.attributionLogo{
                AsyncImage(url: logo) { image in
                    image
                        .resizable()
                        .scaledToFit()
                        .frame(height: 20)
                } placeholder: {
                    Label("Apple Weather", systemImage: "cloud.sun.fill")
                }
            }else{
                ProgressView()
            }
            if let url = self.attributionURL{
                Link("Other data sources", destination: url)
            }else{
                ProgressView()
            }
        }
    }//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
            self.attributionLogo = colorScheme == .light ? attribution.combinedMarkDarkURL : attribution.combinedMarkLightURL
        } catch {
            print("failed to load attribution")
        }
    }//task for logo and link
}//body

}//struct

Edit: AsyncImage returns this image as seen in debug mode: enter image description here

Worked second time after gap of nearly 12 hours enter image description here

The AsyncImage does not display the image even though it is fetched

0

There are 0 best solutions below