-
Notifications
You must be signed in to change notification settings - Fork 437
Open
Description
Describe the bug
I'm trying to show an image in MarkdownUI by using
Markdown("Hallo ", baseURL: docdir, imageBaseURL: docdir)
The image is inside the directory docdir. There is no error shown in the console but only the text "Hallo" shows up. If I use
Markdown("Hallo ", baseURL: docdir, imageBaseURL: docdir)
I get this error in the console:
"LocalDataTask <38A8317F-D044-4C43-B2DB-B6BD271E35EB>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <38A8317F-D044-4C43-B2DB-B6BD271E35EB>.<1>, NSUnderlyingError=0x300e94780 {Error Domain=kCFErrorDomainCFNetwork Code=-1100 "(null)"}}
It seems the directory used for searching the image is correct and the image is found when Image.png is used as the filename.
Checklist
- [ x] I can reproduce this issue with a vanilla SwiftUI project.
- [ x] This bug hasn't been addressed in an existing GitHub issue.
Steps to reproduce
Create a Swift-UI project in Xcode and use this as ContentView.swift
import SwiftUI
import MarkdownUI
let docdir = getDocumentDir()
let copyTask = saveImageToDocuments()
struct ContentView: View {
var body: some View {
VStack {
if(docdir.isFileURL) {
if(!copyTask.isEmpty) {
Markdown("Hallo ", baseURL: docdir, imageBaseURL: docdir)
}
}
}
.padding()
}
}
func getDocumentDir()->URL {
let fileManager = FileManager.default
guard let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
print("Dokumentenordner nicht gefunden")
return URL(fileURLWithPath: "Dokumentenordner nicht gefunden")
}
return documentDirectory
}
func saveImageToDocuments()->String {
guard let image = UIImage(named: "image") else {
print("Bild nicht gefunden")
return "Bild nicht gefunden"
}
guard let imageData = image.pngData() else {
print("Fehler beim Umwandeln des Bildes in Data")
return "Fehler beim Umwandeln des Bildes in Data"
}
let fileManager = FileManager.default
guard let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
print("Dokumentenordner nicht gefunden")
return "Dokumentenordner nicht gefunden"
}
// Dateipfad festlegen (hier PNG-Dateiformat)
let filePath = documentDirectory.appendingPathComponent("Image.png")
do {
try imageData.write(to: filePath)
print("Bild erfolgreich gespeichert unter: \(filePath)")
} catch {
print("Fehler beim Speichern des Bildes: \(error)")
return "Fehler beim Speichern des Bildes: \(error)"
}
return "Bild erfolgreich gespeichert unter: \(filePath)"
}
#Preview {
ContentView()
}
Add MarkdownUI package
Add an image "image" to the asset catalog.
Expected behavior
The image is shown inside the view.
Version information
- MarkdownUI: 2.4.1
- OS: iOS 18.3.1
- Xcode: 16.2
Metadata
Metadata
Assignees
Labels
No labels