I've got a program that trys to download the picture of the day from NASA.
I get download failed, but I know the URL works - here is the output I get
2023-01-27 12:27:18.587287+0000 NASA_APOD[19841:506259] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
2023-01-27 12:27:18.587452+0000 NASA_APOD[19841:506259] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
2023-01-27 12:27:18.587626+0000 NASA_APOD[19841:506259] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
download failed
Any ideas what it all means?
Here is ContentView.swift
//
// ContentView.swift
// NASA_APOD
//
// Created by Gary Watson on 26/01/2023.
//
import SwiftUI
struct ContentView: View {
@State private var pictures = [Picture]()
var body: some View {
List(pictures) { picture in
NavigationLink {
Text(picture.title)
} label: {
Text(picture.date)
}
}
.task {
await fetchMessages()
}
}
func fetchMessages() async {
guard pictures.isEmpty else { return }
do {
let url = URL(string: "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY")!
let (data, _) = try await URLSession.shared.data(from: url)
let decoder = JSONDecoder()
pictures = try decoder.decode([Picture].self, from: data)
} catch {
pictures = []
print("download failed")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
and here is Picture.swift
//
// Picture.swift
// NASA_APOD
//
// Created by Gary Watson on 26/01/2023.
//
import Foundation
struct Picture: Identifiable, Codable {
let id: UUID
let copyright: String?
let date: String
let explanation: String
let hdurl: String
let media_type: String
let service_version: String
let title: String
let url: String
static let example = Picture(id: UUID(), copyright: "Dan Bartlett",
date: "2023-01-27",
explanation: "The current darling of the northern night, Comet C/2022 E3 ZTF is captured in this telescopic image from a dark sky location at June Lake, California. Of course Comet ZTF has been growing brighter in recent days, headed for its closest approach to Earth on February 1. But this view was recorded on January 23, very close to the time planet Earth crossed the orbital plane of long-period Comet ZTF. The comet's broad, whitish dust tail is still curved and fanned out away from the Sun as Comet ZTF sweeps along its orbit. Due to perspective near the orbital plane crossing, components of the fanned out dust tail appear on both sides of the comet's green tinted coma though, to lend Comet ZTF a visually striking (left) anti-tail. Buffeted by solar activity the comet's narrower ion tail also streams away from the coma diagonally to the right, across the nearly three degree wide field of view.",
hdurl: "https://apod.nasa.gov/apod/image/2301/C2022E3ZTF_2023_01_23_054036PST_DEBartlett.jpg",
media_type: "image",
service_version: "v1",
title: "Comet ZTF: Orbital Plane Crossing",
url: "https://apod.nasa.gov/apod/image/2301/C2022E3ZTF_2023_01_23_054036PST_DEBartlett1024.jpg")
}