I want to load a RTFD file (rtf with images) in a WebView.
So I created a file in TextEdit with a text and one image, and saved as doc.rtfd
[
1
In order load the file on SwiftUI I tried the following code:
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ webView: WKWebView, context: Context) {
let request = URLRequest(url: getURL()! )
webView.load(request)
}
public func getURL() -> URL? {
guard let url: URL = Bundle.main.url(forResource: "doc.rtfd.zip", withExtension: nil) else { return nil }
return url
}
}
And then:
struct ExampleWebView: View {
var body: some View {
VStack {
WebView( )
.ignoresSafeArea()
.navigationTitle("RTF View")
.navigationBarTitleDisplayMode(.inline)
Spacer()
}
}
}
But as a result, only the text is displayed correctly. For the image only the name (M2.png) is present:
What I am missing?
